Commit 76afcc95 authored by Forquet Nicolas's avatar Forquet Nicolas
Browse files

close issue #1: hydrus.batch function tested and new processor_load.bat script (for windows 10)

parent 3a8576c9
No related merge requests found
Showing with 91 additions and 62 deletions
+91 -62
hydrus.batch <- function(setup.file, parameter.file HP1 = FALSE){
hydrus.batch <- function(setup.file, parameter.file, HP1 = FALSE, loop.time = 60){
# setup file: json file with setup information
# parameter file: json file with information on the parameter to be modified
# HP1: option to enable HP1
# loop.time: option to adjust the scrutation loop to run several model in parallel
#--------- load necessary libraries ----------#
library(fs)
library(rjson)
......@@ -40,7 +44,6 @@ hydrus.batch <- function(setup.file, parameter.file HP1 = FALSE){
stop("invalid format for simulation.number")
}
#--------- load rhydrus functions --------#
# source the file with the functions dedicated to file manipulation
......@@ -58,9 +61,6 @@ hydrus.batch <- function(setup.file, parameter.file HP1 = FALSE){
dir_copy(path = setup$reference.model.folder,
new_path = paste0(setup$working.folder,"/","simulation","_",as.character(i)), overwrite = TRUE)
# modify input files
modify.input(path = parameter.file, working.foler = setup$working.folder)
# create level_01.dir (and path.dat)
level_01.creator(paste0(setup$working.folder,"/","simulation","_",as.character(i)), HP1 = HP1)
# and copy executable file(s)
......@@ -68,63 +68,91 @@ hydrus.batch <- function(setup.file, parameter.file HP1 = FALSE){
}
#------- modify input files --------#
modify.input(path = parameter.file, working.folder = setup$working.folder)
#-------- start simulations --------#
}
# set the working directory to main.directory
setwd(main.directory)
# nb of simulation to run
nb.runs <- 1
# generic name = the name that will be given to the model that will be run iteratively
# hydrus.folder = the original hydrus folder generated using the GUI
# VERY IMPORTANT = the reference folder MUST contain the HYDRUS exe file !!!
# The option press enter at the end must have been unchecked in the GUI
generic.name <- "PF_Model_"
hydrus.folder <- "DPo_1pulse_modifpdt_180108"
## van Genuchten parameters (here you can enter matrices for the different cases you want to test)
# gravel parameters
deposit = matrix(c(0, 0.05, 0.12, 1.8, 5, 0.5, 0.64, 0.79, 0.05),ncol=9)
# sand parameters
gravel = matrix(c(0, 0.1, 0.572, 2.917, 300, 0.5, 0.052, 0.4, 0),ncol=9)
# create all simulation folders, copy files and modify the one containing the van Genuchten parameters
for (i in 1:nb.runs){
# current simulation name
new.name <- paste(generic.name,as.character(i),sep = "")
# create a copy of the reference model in a folder named as the current simulation
new.hydrus.subfolder(new.name,main.directory,hydrus.folder)
# create the level_01 file
level_01.creator(new.name,main.directory)
# modification of the selector.in file
new.data <- rbind(deposit,gravel)
modify.hydraulic.parameters(new.name,hydrus.folder,new.data,hydrus.version="1D")
}
# computation loop
start.time <- Sys.time()
sim.counter <- 0
while (sim.counter < nb.runs){
# how busy the processor is?
temp <- system('C:/Users/forquet/Documents/script_R/rhydrus/processor_load.bat',intern = TRUE)
processor.usage <- output.bat(temp)
if (processor.usage < 75){
# if processor usage is less than 75%, start a new run
sim.counter <- sim.counter + 1
# go to the simulation working directory
setwd(paste(main.directory,"/",generic.name,as.character(sim.counter),sep=""))
# run Hydrus
system("H1D_Dual.exe", wait = FALSE)
# print the current simulation number
print(sim.counter)
# go back to main directory
setwd(main.directory)
# start measuring computation time
start.time <- Sys.time()
# initialize the simulation counter
sim.counter <- 0
# computation loop
while (sim.counter < setup$simulation.number){
# how busy the processor is?
temp <- system(paste0(setup$rhydrus.folder,"//processor_load.bat"),intern = TRUE)
processor.usage <- output.bat(temp)
if (processor.usage < 75){
# if processor usage is less than 75%, start a new run
sim.counter <- sim.counter + 1
# run Hydrus
system(paste0(setup$working.folder,"/","simulation","_",as.character(i),"//H1D_CALC.exe"), wait = FALSE)
# print the current simulation number
print(sim.counter)
}
# wait loop.time before restarting the loop
Sys.sleep(loop.time)
}
# wait a minute before restarting the loop
Sys.sleep(60)
# stop measuring computation time
end.time <- Sys.time()
}
end.time <- Sys.time()
\ No newline at end of file
# # set the working directory to main.directory
# setwd(main.directory)
#
# # nb of simulation to run
# nb.runs <- 1
#
# # generic name = the name that will be given to the model that will be run iteratively
# # hydrus.folder = the original hydrus folder generated using the GUI
# # VERY IMPORTANT = the reference folder MUST contain the HYDRUS exe file !!!
# # The option press enter at the end must have been unchecked in the GUI
# generic.name <- "PF_Model_"
# hydrus.folder <- "DPo_1pulse_modifpdt_180108"
#
# ## van Genuchten parameters (here you can enter matrices for the different cases you want to test)
# # gravel parameters
# deposit = matrix(c(0, 0.05, 0.12, 1.8, 5, 0.5, 0.64, 0.79, 0.05),ncol=9)
#
# # sand parameters
# gravel = matrix(c(0, 0.1, 0.572, 2.917, 300, 0.5, 0.052, 0.4, 0),ncol=9)
#
# # create all simulation folders, copy files and modify the one containing the van Genuchten parameters
# for (i in 1:nb.runs){
# # current simulation name
# new.name <- paste(generic.name,as.character(i),sep = "")
# # create a copy of the reference model in a folder named as the current simulation
# new.hydrus.subfolder(new.name,main.directory,hydrus.folder)
# # create the level_01 file
# level_01.creator(new.name,main.directory)
# # modification of the selector.in file
# new.data <- rbind(deposit,gravel)
# modify.hydraulic.parameters(new.name,hydrus.folder,new.data,hydrus.version="1D")
# }
#
# # computation loop
# start.time <- Sys.time()
# sim.counter <- 0
#
# while (sim.counter < nb.runs){
# # how busy the processor is?
# temp <- system('C:/Users/forquet/Documents/script_R/rhydrus/processor_load.bat',intern = TRUE)
# processor.usage <- output.bat(temp)
# if (processor.usage < 75){
# # if processor usage is less than 75%, start a new run
# sim.counter <- sim.counter + 1
# # go to the simulation working directory
# setwd(paste(main.directory,"/",generic.name,as.character(sim.counter),sep=""))
# # run Hydrus
# system("H1D_Dual.exe", wait = FALSE)
# # print the current simulation number
# print(sim.counter)
# # go back to main directory
# setwd(main.directory)
# }
# # wait a minute before restarting the loop
# Sys.sleep(60)
# }
# end.time <- Sys.time()
\ No newline at end of file
typeperf "\processeur(_Total)\%% temps processeur" -sc 5
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment