Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
r2ogs6
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ogs
OpenGeoSys Tools
r2ogs6
Commits
e8a681b2
Commit
e8a681b2
authored
4 years ago
by
Ruben Heinrich
Browse files
Options
Downloads
Patches
Plain Diff
[base] Modified run_simulation so it can be used by ensembles later
parent
31f9a628
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
Merge branch 7 fixed functionality into master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/sim_utils.R
+74
-44
74 additions, 44 deletions
R/sim_utils.R
with
74 additions
and
44 deletions
R/sim_utils.R
+
74
−
44
View file @
e8a681b2
...
@@ -6,76 +6,105 @@
...
@@ -6,76 +6,105 @@
#'@description Calls OGS6 object validator functions, exports all necessary
#'@description Calls OGS6 object validator functions, exports all necessary
#' files and starts OpenGeoSys6
#' files and starts OpenGeoSys6
#'@param ogs6_obj OGS6: Simulation object
#'@param ogs6_obj OGS6: Simulation object
#'@param iter_n number: Number of iterations (for simulation chains)
#'@param output_to_log_file flag: Should output be written to a log file?
#'@param output_to_log_file flag: Should output be written to a log file?
#'@export
#'@export
run_simulation
<-
function
(
ogs6_obj
,
iter_n
=
1
,
output_to_log_file
=
TRUE
)
{
run_simulation
<-
function
(
ogs6_obj
,
output_to_log_file
=
TRUE
)
{
assertthat
::
assert_that
(
inherits
(
ogs6_obj
,
"OGS6"
))
assertthat
::
assert_that
(
inherits
(
ogs6_obj
),
"OGS6"
)
assertthat
::
assert_that
(
assertthat
::
is.number
(
iter_n
),
iter_n
>
0
,
iter_n
<
500
)
assertthat
::
assert_that
(
assertthat
::
is.flag
(
output_to_log_file
))
assertthat
::
assert_that
(
assertthat
::
is.flag
(
output_to_log_file
))
#Call all validators
#
Call all validators
validate_all
(
ogs6_obj
)
validate_all
(
ogs6_obj
)
#Export the simulation files
# Create the simulation folder
if
(
!
dir.exists
(
ogs6_obj
$
sim_path
))
{
dir.create
(
ogs6_obj
$
sim_path
)
}
else
{
if
(
length
(
dir
(
ogs6_obj
$
sim_path
,
all.files
=
TRUE
))
!=
0
)
{
warning
(
paste0
(
"The defined sim_path directory '"
,
ogs6_obj
$
sim_path
,
"' is not empty. Files may be overwritten."
),
call.
=
FALSE
)
}
}
# Export the simulation files
export_gml
(
ogs6_obj
)
export_gml
(
ogs6_obj
)
export_prj
(
ogs6_obj
)
export_prj
(
ogs6_obj
)
#Construct the system call
# Construct the system call
ogs6_call
<-
paste0
(
ogs6_obj
$
ogs_bin_path
,
ogs6_call
<-
paste0
(
"ogs.exe "
,
ogs6_obj
$
ogs_bin_path
,
ogs6_obj
$
sim_path
,
"ogs.exe "
,
ogs6_obj
$
sim_name
,
ogs6_obj
$
sim_path
,
".prj -o "
,
ogs6_obj
$
sim_name
,
ogs6_obj
$
sim_path
)
".prj -o "
,
ogs6_obj
$
sim_path
)
# Finally, make the system call to start the simulation
if
(
output_to_log_file
)
{
system
(
command
=
setup_logging
(
ogs6_obj
$
sim_name
,
ogs6_obj
$
sim_path
,
ogs6_call
))
}
else
{
system
(
command
=
ogs6_call
)
}
system_call
<-
ogs6_call
closeAllConnections
()
}
#Direct simulation output to log file
if
(
output_to_log_file
){
# Create logfile directory
#===== LOGGING UTILITY =====
logfile_dir
<-
paste0
(
ogs6
$
sim_path
,
"logfiles/"
)
if
(
!
dir.exists
(
logfile_dir
)){
dir.create
(
logfile_dir
)
}
else
{
warning
(
"Logfile directory already exists"
,
call.
=
FALSE
)
}
for
(
i
in
seq_len
(
iter_n
)){
#'setup_logging
#'@description Sets up logging.
#'@param sim_name string: Simulation name
#'@param sim_path string: Simulation path
#'@param ogs6_call string: Corresponding OGS6 call
setup_logging
<-
function
(
sim_name
,
sim_path
,
ogs6_call
){
logfile_path
<-
paste0
(
logfile_dir
,
assertthat
::
assert_that
(
assertthat
::
is.string
(
sim_name
))
ogs6_obj
$
sim_name
,
assertthat
::
assert_that
(
assertthat
::
is.string
(
sim_path
))
"_log_"
,
iter_n
,
".txt"
)
sim_path
<-
validate_is_dir_path
(
sim_path
)
#Call OGS6
assertthat
::
assert_that
(
assertthat
::
is.string
(
ogs6_call
))
system
(
command
=
paste
(
"R CMD BATCH --no-echo"
,
script_path
,
logfile_path
))
# rea
d_in_output(ogs6_obj)
#
C
rea
te logfile directory
}
logfile_dir
<-
paste0
(
sim_path
,
"logfiles/"
)
#Write to file...
if
(
!
dir.exists
(
logfile_dir
)){
dir.create
(
logfile_dir
)
}
}
#Run simulations (and read in output as input)
# Create initialization script
for
(
i
in
seq_len
(
iter_n
)){
script_path
<-
paste0
(
logfile_dir
,
"sim_init.R"
)
#Call OGS6
system
(
command
=
ogs6_call
)
# read_in_output(ogs6_obj)
if
(
!
file.exists
(
script_path
)){
file.create
(
script_path
)
}
}
closeAllConnections
()
cmd_str
<-
paste0
(
"system(command = \""
,
ogs6_call
,
"\")"
)
file_conn
<-
file
(
script_path
)
writeLines
(
c
(
cmd_str
),
file_conn
)
close
(
file_conn
)
# Return string for calling R CMD BATCH
batch_call
<-
paste0
(
"R CMD BATCH --no-echo "
,
script_path
,
" "
,
sim_name
,
"_log.txt"
)
return
(
invisible
(
batch_call
))
}
}
#===== V
ALIDATION UTILITY
=====
#===== V
alidation utility
=====
#'validate_all
#'validate_all
...
@@ -103,7 +132,7 @@ validate_all <- function(ogs6_obj) {
...
@@ -103,7 +132,7 @@ validate_all <- function(ogs6_obj) {
}
}
#===== C
HAINING UTILITY
(WIP) =====
#===== C
haining utility
(WIP) =====
#'read_in_output
#'read_in_output
...
@@ -118,3 +147,4 @@ read_in_output <- function(ogs6_obj) {
...
@@ -118,3 +147,4 @@ read_in_output <- function(ogs6_obj) {
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment