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
1a24f7fe
Commit
1a24f7fe
authored
4 years ago
by
Ruben Heinrich
Browse files
Options
Downloads
Patches
Plain Diff
[feature] Improved logging
parent
b33eab90
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
+32
-59
32 additions, 59 deletions
R/sim_utils.R
with
32 additions
and
59 deletions
R/sim_utils.R
+
32
−
59
View file @
1a24f7fe
...
...
@@ -6,12 +6,12 @@
#'@description Calls OGS6 object validator functions, exports all necessary
#' files and starts OpenGeoSys6
#'@param ogs6_obj OGS6: Simulation object
#'@param
output_to
_log
_
file flag: Should output be written to a log
file?
#'@param
write
_logfile flag: Should output be written to a logfile?
#'@export
run_simulation
<-
function
(
ogs6_obj
,
output_to
_log
_
file
=
TRUE
)
{
run_simulation
<-
function
(
ogs6_obj
,
write
_logfile
=
TRUE
)
{
assertthat
::
assert_that
(
inherits
(
ogs6_obj
)
,
"OGS6"
)
assertthat
::
assert_that
(
assertthat
::
is.flag
(
output_to
_log
_
file
))
assertthat
::
assert_that
(
inherits
(
ogs6_obj
,
"OGS6"
)
)
assertthat
::
assert_that
(
assertthat
::
is.flag
(
write
_logfile
))
# Call all validators
validate_all
(
ogs6_obj
)
...
...
@@ -20,7 +20,7 @@ run_simulation <- function(ogs6_obj, output_to_log_file = TRUE) {
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
)
{
if
(
length
(
list.files
(
ogs6_obj
$
sim_path
,
all.files
=
TRUE
))
!=
0
)
{
warning
(
paste0
(
"The defined sim_path directory '"
,
...
...
@@ -36,71 +36,44 @@ run_simulation <- function(ogs6_obj, output_to_log_file = TRUE) {
export_gml
(
ogs6_obj
)
export_prj
(
ogs6_obj
)
# Construct the system call
ogs6_call
<-
paste0
(
ogs6_obj
$
ogs_bin_path
,
"ogs.exe "
,
ogs6_obj
$
sim_path
,
ogs6_obj
$
sim_name
,
".prj -o "
,
ogs6_obj
$
sim_path
)
# Construct the call
ogs6_command_str
<-
paste0
(
ogs6_obj
$
ogs_bin_path
,
"ogs.exe"
)
sim_path_full
<-
paste0
(
ogs6_obj
$
sim_path
,
ogs6_obj
$
sim_name
,
".prj"
)
ogs6_args
<-
c
(
sim_path_full
,
"-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
)
}
closeAllConnections
()
}
#===== LOGGING UTILITY =====
exit_code
<-
0
# Finally, make the system call to start the simulation
if
(
write_logfile
)
{
#'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
){
assertthat
::
assert_that
(
assertthat
::
is.string
(
sim_name
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
sim_path
))
sim_path
<-
validate_is_dir_path
(
sim_path
)
assertthat
::
assert_that
(
assertthat
::
is.string
(
ogs6_call
))
# Create logfile directory
logfile_dir
<-
paste0
(
ogs6_obj
$
sim_path
,
"logfiles/"
)
#
Create
logfile
directory
logfile
_dir
<-
paste0
(
sim_path
,
"log
files/
"
)
#
Set
logfile
parameter of simulation object
ogs6_obj
$
logfile
<-
paste0
(
logfile_dir
,
ogs6_obj
$
sim_name
,
"
_
log
.txt
"
)
if
(
!
dir.exists
(
logfile_dir
)){
dir.create
(
logfile_dir
)
}
if
(
!
dir.exists
(
logfile_dir
)){
dir.create
(
logfile_dir
)
}
# Create initialization script
script_path
<-
paste0
(
logfile_dir
,
"sim_init.R"
)
assertthat
::
assert_that
(
!
file.exists
(
ogs6_obj
$
logfile
))
file.create
(
ogs6_obj
$
logfile
)
if
(
!
file.exists
(
script_path
)){
file.create
(
script_path
)
exit_code
<-
system2
(
command
=
ogs6_command_str
,
args
=
ogs6_args
,
stdout
=
ogs6_obj
$
logfile
)
}
else
{
exit_code
<-
system2
(
command
=
ogs6_command_str
,
args
=
ogs6_args
)
}
cmd_str
<-
paste0
(
"system(command = \""
,
ogs6_call
,
"\")"
)
file_conn
<-
file
(
script_path
)
writeLines
(
c
(
cmd_str
),
file_conn
)
close
(
file_conn
)
closeAllConnections
()
# Return string for calling R CMD BATCH
batch_call
<-
paste0
(
"R CMD BATCH --no-echo "
,
script_path
,
" "
,
sim_name
,
"_log.txt"
)
cat
(
"\nCaught exit code"
,
exit_code
,
"\n"
)
return
(
invisible
(
batch_call
))
return
(
invisible
(
exit_code
))
}
...
...
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