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
065645e8
Commit
065645e8
authored
4 years ago
by
Ruben Heinrich
Browse files
Options
Downloads
Patches
Plain Diff
[base] generate_all_benchmark_scripts now with tryCatch
parent
18318bbe
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/generate_benchmark_script.R
+83
-47
83 additions, 47 deletions
R/generate_benchmark_script.R
with
83 additions
and
47 deletions
R/generate_benchmark_script.R
+
83
−
47
View file @
065645e8
...
@@ -8,20 +8,20 @@
...
@@ -8,20 +8,20 @@
#'@param path string: Path to a benchmark directory to generate scripts from
#'@param path string: Path to a benchmark directory to generate scripts from
#'@param sim_path string: Path where all simulation files will be saved
#'@param sim_path string: Path where all simulation files will be saved
#'@param scripts_path string: Path where benchmark scripts will be saved
#'@param scripts_path string: Path where benchmark scripts will be saved
#'@param starting_from_prj_path string: Optional:
#'@param skip_prj_paths character: Optional: .prj paths to skip
#'@param read_in_vtus flag: Optional: Should .vtu files just be copied or read
#' in too?
#'@param read_in_gmls flag: Optional: Should .gml files just be copied or read
#'@param read_in_gmls flag: Optional: Should .gml files just be copied or read
#' in too?
#' in too?
#'@param read_in_vtus flag: Optional: Should .vtu files just be copied or read
#' in too?
#'@param starting_from_prj_path string: Optional:
#'@param skip_prj_paths character: Optional: .prj paths to skip
generate_all_benchmark_scripts
<-
generate_all_benchmark_scripts
<-
function
(
path
,
function
(
path
,
sim_path
,
sim_path
,
scripts_path
,
scripts_path
,
starting_from_prj_path
=
""
,
read_in_gmls
,
skip_prj_paths
=
character
(),
read_in_vtus
=
FALSE
,
read_in_vtus
=
FALSE
,
read_in_gmls
=
TRUE
){
starting_from_prj_path
=
""
,
skip_prj_paths
=
character
()){
if
(
missing
(
path
)){
if
(
missing
(
path
)){
path
<-
unlist
(
options
(
"r2ogs6.default_benchmark_path"
))
path
<-
unlist
(
options
(
"r2ogs6.default_benchmark_path"
))
...
@@ -35,6 +35,8 @@ generate_all_benchmark_scripts <-
...
@@ -35,6 +35,8 @@ generate_all_benchmark_scripts <-
scripts_path
<-
unlist
(
options
(
"r2ogs6.default_script_path"
))
scripts_path
<-
unlist
(
options
(
"r2ogs6.default_script_path"
))
}
}
missing_read_in_gmls
<-
missing
(
read_in_gmls
)
path
<-
validate_is_dir_path
(
path
)
path
<-
validate_is_dir_path
(
path
)
scripts_path
<-
validate_is_dir_path
(
scripts_path
)
scripts_path
<-
validate_is_dir_path
(
scripts_path
)
assertthat
::
assert_that
(
assertthat
::
is.string
(
starting_from_prj_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
starting_from_prj_path
))
...
@@ -52,6 +54,7 @@ generate_all_benchmark_scripts <-
...
@@ -52,6 +54,7 @@ generate_all_benchmark_scripts <-
}
}
invalid_xml_paths
<-
character
()
invalid_xml_paths
<-
character
()
invalid_prj_paths
<-
character
()
for
(
i
in
seq_len
(
length
(
prj_paths
))){
for
(
i
in
seq_len
(
length
(
prj_paths
))){
...
@@ -59,8 +62,8 @@ generate_all_benchmark_scripts <-
...
@@ -59,8 +62,8 @@ generate_all_benchmark_scripts <-
next
next
}
}
skip_
to_next
<-
FALSE
skip_
generate
<-
FALSE
invalid_xml_path
<-
""
generate_failed
<-
FALSE
out
<-
tryCatch
(
out
<-
tryCatch
(
{
{
...
@@ -68,17 +71,19 @@ generate_all_benchmark_scripts <-
...
@@ -68,17 +71,19 @@ generate_all_benchmark_scripts <-
encoding
=
"ISO-8859-1"
)
encoding
=
"ISO-8859-1"
)
},
},
error
=
function
(
cond
){
error
=
function
(
cond
){
skip_to_next
<<-
TRUE
message
(
paste
(
"\nxml2::read_xml() failed for"
,
invalid_xml_path
<<-
prj_paths
[[
i
]]
prj_paths
[[
i
]],
". Original error message:"
))
message
(
cond
)
skip_generate
<<-
TRUE
}
}
)
)
if
(
skip_
to_next
){
if
(
skip_
generate
){
invalid_xml_paths
<-
c
(
invalid_xml_paths
,
invalid_xml_path
)
invalid_xml_paths
<-
c
(
invalid_xml_paths
,
prj_paths
[[
i
]]
)
next
next
}
}
cat
(
"\nGenerating script from path"
,
prj_paths
[[
i
]])
#
cat("\nGenerating script from path", prj_paths[[i]])
# Put simulations in their own subfolders under sim_path
# Put simulations in their own subfolders under sim_path
sim_subdir
<-
sim_subdir
<-
...
@@ -86,17 +91,36 @@ generate_all_benchmark_scripts <-
...
@@ -86,17 +91,36 @@ generate_all_benchmark_scripts <-
basename
(
dirname
(
prj_paths
[[
i
]])),
"_"
,
basename
(
dirname
(
prj_paths
[[
i
]])),
"_"
,
tools
::
file_path_sans_ext
(
basename
(
prj_paths
[[
i
]])))
tools
::
file_path_sans_ext
(
basename
(
prj_paths
[[
i
]])))
generate_benchmark_script
(
prj_path
=
prj_paths
[[
i
]],
out
<-
tryCatch
(
sim_path
=
sim_subdir
,
{
script_path
=
scripts_path
,
if
(
missing_read_in_gmls
){
read_in_vtu
=
read_in_vtus
,
generate_benchmark_script
(
prj_path
=
prj_paths
[[
i
]],
read_in_gml
=
read_in_gmls
)
sim_path
=
sim_subdir
,
}
script_path
=
scripts_path
,
read_in_vtu
=
read_in_vtus
)
}
else
{
generate_benchmark_script
(
prj_path
=
prj_paths
[[
i
]],
sim_path
=
sim_subdir
,
script_path
=
scripts_path
,
read_in_gml
=
read_in_gmls
,
read_in_vtu
=
read_in_vtus
)
}
},
error
=
function
(
cond
){
message
(
paste
(
"\ngenerate_benchmark_script() failed for"
,
prj_paths
[[
i
]],
". Original error message:"
))
message
(
cond
)
generate_failed
<<-
TRUE
}
)
cat
(
"\nFailed parsing the following files:"
)
if
(
generate_failed
){
print
(
invalid_xml_paths
)
invalid_prj_paths
<-
c
(
invalid_prj_paths
,
prj_paths
[[
i
]])
}
}
return
(
invisible
())
return
(
invisible
(
list
(
invalid_xml_paths
,
invalid_prj_paths
)
))
}
}
...
@@ -109,17 +133,17 @@ generate_all_benchmark_scripts <-
...
@@ -109,17 +133,17 @@ generate_all_benchmark_scripts <-
#'@param sim_path string: Path where all simulation files will be saved
#'@param sim_path string: Path where all simulation files will be saved
#'@param ogs_bin_path string: OpenGeoSys bin folder path
#'@param ogs_bin_path string: OpenGeoSys bin folder path
#'@param script_path string: Path where benchmark script will be saved
#'@param script_path string: Path where benchmark script will be saved
#'@param read_in_vtu flag: Optional: Should .vtu file(s) just be copied or read
#' in too?
#'@param read_in_gml flag: Optional: Should .gml file just be copied or read
#'@param read_in_gml flag: Optional: Should .gml file just be copied or read
#' in too?
#' in too?
#'@param read_in_vtu flag: Optional: Should .vtu file(s) just be copied or read
#' in too?
#'@export
#'@export
generate_benchmark_script
<-
function
(
prj_path
,
generate_benchmark_script
<-
function
(
prj_path
,
sim_path
,
sim_path
,
ogs_bin_path
,
ogs_bin_path
,
script_path
,
script_path
,
read_in_
vtu
=
FALSE
,
read_in_
gml
,
read_in_
gml
=
TRU
E
)
{
read_in_
vtu
=
FALS
E
)
{
if
(
missing
(
ogs_bin_path
)){
if
(
missing
(
ogs_bin_path
)){
ogs_bin_path
<-
unlist
(
options
(
"r2ogs6.default_ogs_bin_path"
))
ogs_bin_path
<-
unlist
(
options
(
"r2ogs6.default_ogs_bin_path"
))
...
@@ -129,12 +153,12 @@ generate_benchmark_script <- function(prj_path,
...
@@ -129,12 +153,12 @@ generate_benchmark_script <- function(prj_path,
script_path
<-
unlist
(
options
(
"r2ogs6.default_script_path"
))
script_path
<-
unlist
(
options
(
"r2ogs6.default_script_path"
))
}
}
assertthat
::
assert_that
(
assertthat
::
is.string
(
prj_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
prj_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
sim_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
sim_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
ogs_bin_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
ogs_bin_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
script_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
script_path
))
assertthat
::
assert_that
(
assertthat
::
is.flag
(
read_in_vtu
))
assertthat
::
assert_that
(
assertthat
::
is.flag
(
read_in_vtu
))
assertthat
::
assert_that
(
assertthat
::
is.flag
(
read_in_gml
))
#Construct an object from a benchmark and then reverse engineer the call
#Construct an object from a benchmark and then reverse engineer the call
ogs6_obj
<-
OGS6
$
new
(
sim_name
=
""
,
ogs6_obj
<-
OGS6
$
new
(
sim_name
=
""
,
...
@@ -146,9 +170,9 @@ generate_benchmark_script <- function(prj_path,
...
@@ -146,9 +170,9 @@ generate_benchmark_script <- function(prj_path,
read_in_prj
(
ogs6_obj
,
read_in_prj
(
ogs6_obj
,
prj_path
,
prj_path
,
read_in_vtu
,
read_in_vtu
,
read_in_gml
)
read_in_gml
=
FALSE
)
impl_classes
=
get_implemented_classe
s
()
prj_components
=
addable_prj_component
s
()
sim_name
<-
tools
::
file_path_sans_ext
(
basename
(
prj_path
))
sim_name
<-
tools
::
file_path_sans_ext
(
basename
(
prj_path
))
...
@@ -160,13 +184,29 @@ generate_benchmark_script <- function(prj_path,
...
@@ -160,13 +184,29 @@ generate_benchmark_script <- function(prj_path,
"ogs_bin_path = \""
,
ogs_bin_path
,
"\")\n\n\n"
)
"ogs_bin_path = \""
,
ogs_bin_path
,
"\")\n\n\n"
)
# If there is a .gml but it shouldn't be read in, add reference
# If there is a .gml but it shouldn't be read in, add reference
if
(
!
is.null
(
ogs6_obj
$
geometry
)
&&
!
read_in_gml
)
{
if
(
!
is.null
(
ogs6_obj
$
geometry
))
{
script_str
<-
paste0
(
script_str
,
# If read_in_gml isn't supplied, check number of lines in .gml file
"ogs6_obj$add_gml("
,
# since string concatenation is slow
construct_add_call
(
ogs6_obj
$
geometry
),
if
(
missing
(
read_in_gml
)){
")\n\n"
read_in_gml
<-
(
length
(
readLines
(
ogs6_obj
$
geometry
))
<=
)
unlist
(
options
(
"r2ogs6.max_lines_gml"
)))
}
assertthat
::
assert_that
(
assertthat
::
is.flag
(
read_in_gml
))
if
(
!
read_in_gml
){
script_str
<-
paste0
(
script_str
,
"ogs6_obj$add_gml("
,
construct_add_call
(
ogs6_obj
$
geometry
),
")\n\n"
)
}
else
{
ogs6_obj
$
add_gml
(
read_in_gml
(
ogs6_obj
$
geometry
))
script_str
<-
paste0
(
script_str
,
construct_add_call
(
ogs6_obj
$
gml
),
"\n\n"
)
}
}
}
# Add .vtu references and optionally, OGS6_vtu objects
# Add .vtu references and optionally, OGS6_vtu objects
...
@@ -179,14 +219,9 @@ generate_benchmark_script <- function(prj_path,
...
@@ -179,14 +219,9 @@ generate_benchmark_script <- function(prj_path,
}
}
# Add class objects (and such in wrapper lists)
# Add class objects (and such in wrapper lists)
for
(
i
in
seq_len
(
length
(
impl_classes
))){
for
(
i
in
seq_len
(
length
(
prj_components
))){
# We already handled the .vtus above
if
(
impl_classes
[[
i
]]
==
"OGS6_vtu"
){
next
}
get_component_call
<-
paste0
(
"ogs6_obj$"
,
names
(
impl_classe
s
)[[
i
]])
get_component_call
<-
paste0
(
"ogs6_obj$"
,
names
(
prj_component
s
)[[
i
]])
ogs6_component
<-
eval
(
parse
(
text
=
get_component_call
))
ogs6_component
<-
eval
(
parse
(
text
=
get_component_call
))
# If benchmark doesn't have components of specified name, skip
# If benchmark doesn't have components of specified name, skip
...
@@ -201,9 +236,10 @@ generate_benchmark_script <- function(prj_path,
...
@@ -201,9 +236,10 @@ generate_benchmark_script <- function(prj_path,
}
}
for
(
j
in
seq_along
(
ogs6_component
)){
for
(
j
in
seq_along
(
ogs6_component
)){
add_call_str
<-
paste0
(
construct_add_call
(
ogs6_component
[[
j
]]),
script_str
<-
"\n\n"
)
paste0
(
script_str
,
script_str
<-
paste0
(
script_str
,
add_call_str
)
paste0
(
construct_add_call
(
ogs6_component
[[
j
]]),
"\n\n"
))
}
}
}
}
...
...
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