Hi, I'm researcher in South Korea.
First, Thank for developing and sharing hydromad.
Now, I'm working on SWMM parameter auto-calibration using R(Package SWMMR and hydromad).
Code is attached in this massage.
The question is, like title in this massage, is there any way to speed up the processing?
If the number of variables applied to
auto-calibration exceeds about 200, the calculation speed becomes very slow.
Is there any way to speed up like multicore processing or GPU processing.
------------------------------------------------------------------------------------------------------------------------------------
install.packages(c("zoo", "latticeExtra", "polynom", "car", "Hmisc","reshape"))
install.packages("hydromad", repos="
http://hydromad.catchment.org")
install.packages("swmmr") #install packages
install.packages("readxl")
install.packages("xts")
install.packages("openxlsx")
library(package = "hydromad")
library(swmmr)
library(openxlsx)
library(readxl)
library(xts)
setwd("C:/Users/DS266/Downloads/optimization/test_sh") #Assign working directory
inp_file<-file.path("C:/Users/DS266/Downloads/optimization/test_sh/samho2.inp") #Read initial input file
swmm_file<-run_swmm(inp_file)
obs<-read_xlsx("obs2.xlsx")
obs2<-xts(obs$V1,
order.by=obs$...1) #write.csv(as.data.frame(obs),"obs.csv")
inp<-read_inp(swmm_file$inp)
nse <- function(x){1-sum((x[,1]-x[,2])^2)/sum((x[,1]-mean(x[,1]))^2)}
obj_fun <- function(x, inp, obs2){
inp$subcatchments <- within(inp$subcatchments,{
Perc_Imperv<-x[1:107]
Width<-x[108:214]
})
inp$subareas<-within(inp$subareas,{
"N-Imperv"<-x[215]
"N-Perv"<-x[216]
"S-Imperv"<-x[217]
"S-Perv"<-x[218]
PctZero<-x[219]
})
inp$infiltration<-within(inp$infiltration,{
MaxRate<-x[220]
MinRate<-x[221]
Decay<-x[222]
})
inp$conduits<-within(inp$conduits,{
Roughness<-x[223]
})
# inp$infiltration<-within(inp$infiltration,{
# DryTime<-x[224]
# })
# inp$subcatchments <- within(inp$subcatchments,{
# Perc_Slope<-x[225]
# })
# tmp_inp<-file.path("C:/Users/DS266/Downloads/optimization/test_sh/inp/sh2.inp")
tmp_inp<-tempfile()
write_inp(inp, tmp_inp)
swmm_file<-suppressMessages(run_swmm(tmp_inp, stdout = NULL))
on.exit(file.remove(unlist(swmm_file)))
sim<-read_out(swmm_file$out,
iType = 2,
object_name = "1036-7500",
vIndex = 0)[["1036-7500"]]$flow_rate
nse(merge(obs2,sim))*-1
}
set.seed(1234)
system.time({sce<-SCEoptim(
obj_fun,
par=c(inp[["subcatchments"]][["Perc_Imperv"]], #Perc_Imperv
inp[["subcatchments"]][["Width"]], #Width
0.03, #N-Imperv
0.3, #N-Perv
2.5, #S-Imperv
5.0, #S-Perv
10, #PctZero
254, #Max_R
25.4, #Min_R
2, #Decay
0.015), #Manning
lower=c(inp[["subcatchments"]][["Perc_Imperv"]]*0.5, #Perc_Imperv
inp[["subcatchments"]][["Width"]]*0.5, #Width
0.011, #N-Imperv
0.1, #N-Perv
1.6, #S-Imperv
3.8, #S-Perv
10, #PctZero
76, #Max_R
2.5, #Min_R
1, #Decay
0.011 ), #Manning
upper=c(inp[["subcatchments"]][["Perc_Imperv"]]*1.5, #Perc_Imperv
inp[["subcatchments"]][["Width"]]*1.5, #Width
0.02, #N-Imperv
0.35, #N-Perv
3.8, #S-Imperv
6.4, #S-Perv
30, #PctZero
254, #Max_R
25.4, #Min_R
4, #Decay
0.02), #Manning
control = list(
trace=1,
ncomplex=20,
maxit=3),
inp=inp,
obs=obs2
)})
summary(calibration_res)