-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathepanet_api_v003.R
162 lines (117 loc) · 5.67 KB
/
epanet_api_v003.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#...............................................................................
# 1. - Initialize Session ####
#...............................................................................
cat("\014")
rm(list=ls())
# Installs libraries
library(tidyverse)
library(zoo)
library(lubridate)
library(epanetReader)
library(epanet2toolkit)
library(ggfortify)
library(ggthemes)
library(scales)
#library(reshape2)
# Initialize params
params <- list(net_works = "prv_01",
inlet_valves = c("PRV_001"),
time_step = "hour",
pattern_start = "2020-1-1 00:30",
pattern_end = "2020-1-1 23:30",
jt_to_analyze = "^JT_0[A-K]", # RegExp
main_nodes = c("JT_0A_001", "JT_0K_011"),
emitter_coeff = 1/10000)
demad_factor <- list( c( "wd_spring_summer","hw_spring_summer",
"wd_summer_break","hw_summer_break",
"wd_fall_winter","hw_fall_winter"),
c( 0.92, 1.00, 1.09, 0.81, 0.66, 0.95))
# initialize files paths and files
dir_work <- getwd()
dir_report <- file.path(dir_work,"reports")
dir_data <- file.path(dir_work,"data")
dir_bin <- file.path(dir_work,"reports")
dir_func <- file.path(dir_work,"func")
file_inp <- file.path(dir_data, paste0(params$net_work,".inp"))
file_report <- file.path(dir_report, paste0(params$net_work,".rpt"))
file_bin <- file.path(dir_report, paste0(params$net_work,".bin"))
file_func <- file.path(dir_func, "epanet_api_functions.R")
# Load Functions Standard
source(file_func)
# Read network information from an *.inp
net_input_01 <- read.inp(file_inp)
# glimpse(net_input_01)
#...............................................................................
# LEAKAGE
#...............................................................................
junctions_base <- gen_emitter (inp_file = net_input_01,
emitter_base = 0,
id_junctions = params$jt_to_analyze)
emiter_coef <- junctions_base %>% select(ID, Emitter_C, Length)
net_input_01$Emitters <- data.frame(ID = junctions_base$ID,
FlowCoef = junctions_base$FlowCoef)
write.inp(net_input_01, file.path(dir_data,"Net_fromR_01.inp"))
#...............................................................................
# Times of net input
#...............................................................................
net_times <- net_input_01$Times
names(net_times) <- c("duration", "hydraulic_timestep", "quality_timestep",
"pattern_timestep", "pattern_start", "report_timestep",
"report_start", "start_clock_time", "statistic")
#...............................................................................
# Plot Network
#...............................................................................
# plot(net_input_01, plot.labels=TRUE)
#...............................................................................
# Plot NODAL Demand Patterns
# nd <- Nodal demands,
# wd <- Workdays
# hw <- weekdays and holidays
# rh <- reservoir heads,
# ps <- pump schedules,
# wq <- water quality
#...............................................................................
patterns <- as.tibble(net_input_01$Patterns) %>%
select(starts_with("nd")) %>%
as.zoo(idx)
plot_ts_curves(patterns,
y_limits = c(0.0,2.0),
m_title = "NODAL DEMAND PATTERNS",
y_lab = "Multiplier (Avg. = 1.0)")
#...............................................................................
# 2. Running a Full Simulation ####
# The function ENepanet() runs a full simulation and
# writes the results to a file.
#...............................................................................
ENepanet(file_inp, file_report)
net_report_01 <- read.rpt(file_report)
# glimpse(net_report_01)
#...............................................................................
# The .rpt file generated by Epanet may be read into R using read.rpt().
# The simulation is summarized over junctions, tanks and pipes.
#...............................................................................
# inhabitants = aprox. 10,000
# consum about 125 l/hab/day
# round(sum(inlet_flow)*((60*60)/125.0),0)
inlet_flow <- tab_reports( report = net_report_01,
results = "links",
type = "PRV",
id = params$inlet_valves,
value = "Flow",
summary = FALSE)
plot_ts_curves(inlet_flow,
y_limits = c(0.0,25),
m_title = "INLET FLOW (l/s)",
y_lab = "Flow (l/s)")
#-------------------------------------------------------------------------------
jt_pressure <- tab_reports( report = net_report_01,
results = "nodes",
type = "Junction",
id = params$jt_to_analyze,
value = "Pressure",
summary = TRUE)
#...............................................................................
# ACTUAL STATUS MARKER !!!!!!!
# https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
# git push origin master
#...............................................................................