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
3ecc6623
Commit
3ecc6623
authored
4 years ago
by
Ruben Heinrich
Browse files
Options
Downloads
Patches
Plain Diff
[base] default paths called from options() now
parent
8557e3e6
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
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
R/generate_benchmark_script.R
+13
-24
13 additions, 24 deletions
R/generate_benchmark_script.R
R/ogs6.R
+9
-2
9 additions, 2 deletions
R/ogs6.R
R/read_in_utils.R
+3
-3
3 additions, 3 deletions
R/read_in_utils.R
R/sim_utils.R
+65
-40
65 additions, 40 deletions
R/sim_utils.R
with
90 additions
and
69 deletions
R/generate_benchmark_script.R
+
13
−
24
View file @
3ecc6623
...
@@ -14,8 +14,6 @@
...
@@ -14,8 +14,6 @@
#' in too?
#' 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 test_mode flag: Optional: In test mode, if `path` is missing,
#' internal function `get_default_benchmark_path()` will be called
generate_all_benchmark_scripts
<-
generate_all_benchmark_scripts
<-
function
(
path
,
function
(
path
,
sim_path
,
sim_path
,
...
@@ -23,21 +21,18 @@ generate_all_benchmark_scripts <-
...
@@ -23,21 +21,18 @@ generate_all_benchmark_scripts <-
starting_from_prj_path
=
""
,
starting_from_prj_path
=
""
,
skip_prj_paths
=
character
(),
skip_prj_paths
=
character
(),
read_in_vtus
=
FALSE
,
read_in_vtus
=
FALSE
,
read_in_gmls
=
TRUE
,
read_in_gmls
=
TRUE
){
test_mode
=
FALSE
){
assertthat
::
assert_that
(
assertthat
::
is.flag
(
test_mode
))
if
(
missing
(
path
)){
path
<-
options
(
"r2ogs6.default_benchmark_path"
)
if
(
missing
(
path
)
&&
test_mode
){
path
<-
get_default_benchmark_path
()
}
}
if
(
missing
(
sim_path
)
&&
test_mode
){
if
(
missing
(
sim_path
)){
sim_path
<-
get_
default_sim_path
(
)
sim_path
<-
options
(
"r2ogs6.
default_sim_path
"
)
}
}
if
(
missing
(
scripts_path
)
&&
test_mode
){
if
(
missing
(
scripts_path
)){
scripts_path
<-
get_
default_script_path
(
)
scripts_path
<-
options
(
"r2ogs6.
default_script_path
"
)
}
}
path
<-
validate_is_dir_path
(
path
)
path
<-
validate_is_dir_path
(
path
)
...
@@ -95,8 +90,7 @@ generate_all_benchmark_scripts <-
...
@@ -95,8 +90,7 @@ generate_all_benchmark_scripts <-
sim_path
=
sim_subdir
,
sim_path
=
sim_subdir
,
script_path
=
scripts_path
,
script_path
=
scripts_path
,
read_in_vtu
=
read_in_vtus
,
read_in_vtu
=
read_in_vtus
,
read_in_gml
=
read_in_gmls
,
read_in_gml
=
read_in_gmls
)
test_mode
=
test_mode
)
}
}
cat
(
"\nFailed parsing the following files:"
)
cat
(
"\nFailed parsing the following files:"
)
...
@@ -119,25 +113,20 @@ generate_all_benchmark_scripts <-
...
@@ -119,25 +113,20 @@ generate_all_benchmark_scripts <-
#' in too?
#' 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 test_mode flag: Optional: In test mode, if `ogs_bin_path` is missing,
#' internal function `get_default_ogs_bin_path()` will be called
#'@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_vtu
=
FALSE
,
read_in_gml
=
TRUE
,
read_in_gml
=
TRUE
)
{
test_mode
=
FALSE
)
{
assertthat
::
assert_that
(
assertthat
::
is.flag
(
test_mode
))
if
(
missing
(
ogs_bin_path
)
&&
test_mode
){
if
(
missing
(
ogs_bin_path
)){
ogs_bin_path
<-
get_
default_
ogs_
bin_path
(
)
ogs_bin_path
<-
options
(
"r2ogs6.
default_bin_path
"
)
}
}
if
(
missing
(
script_path
)
&&
test_mode
){
if
(
missing
(
script_path
)){
script_path
<-
get_
default_script_path
(
)
script_path
<-
options
(
"r2ogs6.
default_script_path
"
)
}
}
assertthat
::
assert_that
(
assertthat
::
is.string
(
prj_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
prj_path
))
...
...
This diff is collapsed.
Click to expand it.
R/ogs6.R
+
9
−
2
View file @
3ecc6623
...
@@ -27,7 +27,14 @@ OGS6 <- R6::R6Class("OGS6",
...
@@ -27,7 +27,14 @@ OGS6 <- R6::R6Class("OGS6",
assertthat
::
assert_that
(
assertthat
::
is.number
(
sim_id
))
assertthat
::
assert_that
(
assertthat
::
is.number
(
sim_id
))
self
$
sim_name
<-
sim_name
self
$
sim_name
<-
sim_name
self
$
sim_path
<-
sim_path
if
(
missing
(
sim_path
)){
sim_path
<-
options
(
"r2ogs6.default_sim_path"
)
}
if
(
missing
(
ogs_bin_path
)){
ogs_bin_path
<-
options
(
"r2ogs6.default_ogs_bin_path"
)
}
if
(
!
test_mode
){
if
(
!
test_mode
){
if
(
!
file.exists
(
paste0
(
ogs_bin_path
,
"generateStructuredMesh.exe"
)))
{
if
(
!
file.exists
(
paste0
(
ogs_bin_path
,
"generateStructuredMesh.exe"
)))
{
...
@@ -37,8 +44,8 @@ OGS6 <- R6::R6Class("OGS6",
...
@@ -37,8 +44,8 @@ OGS6 <- R6::R6Class("OGS6",
}
}
}
}
private
$
.sim_name
<-
sim_name
private
$
.sim_id
<-
sim_id
private
$
.sim_id
<-
sim_id
self
$
sim_path
<-
sim_path
private
$
.ogs_bin_path
<-
validate_is_dir_path
(
ogs_bin_path
)
private
$
.ogs_bin_path
<-
validate_is_dir_path
(
ogs_bin_path
)
},
},
...
...
This diff is collapsed.
Click to expand it.
R/read_in_utils.R
+
3
−
3
View file @
3ecc6623
...
@@ -107,7 +107,7 @@ read_in <- function(ogs6_obj,
...
@@ -107,7 +107,7 @@ read_in <- function(ogs6_obj,
add_call
<-
paste0
(
"ogs6_obj$add_"
,
child_name
,
"(r2ogs6_obj)"
)
add_call
<-
paste0
(
"ogs6_obj$add_"
,
child_name
,
"(r2ogs6_obj)"
)
#Parse all children
#Parse all children
for
(
i
in
seq_
along
(
nodes
))
{
for
(
i
in
seq_
len
(
length
(
nodes
))
)
{
r2ogs6_obj
<-
node_to_r2ogs6_obj
(
nodes
[[
i
]],
r2ogs6_obj
<-
node_to_r2ogs6_obj
(
nodes
[[
i
]],
xpath_expr
,
xpath_expr
,
...
@@ -144,7 +144,7 @@ node_to_r2ogs6_obj <- function(xml_node,
...
@@ -144,7 +144,7 @@ node_to_r2ogs6_obj <- function(xml_node,
parameters
<-
c
(
parameters
,
xml2
::
xml_attrs
(
xml_node
))
parameters
<-
c
(
parameters
,
xml2
::
xml_attrs
(
xml_node
))
}
}
for
(
i
in
seq_
along
(
parameter_nodes
)){
for
(
i
in
seq_
len
(
length
(
parameter_nodes
))
)
{
new_xpath_expr
<-
paste0
(
xpath_expr
,
new_xpath_expr
<-
paste0
(
xpath_expr
,
"/"
,
"/"
,
...
@@ -324,7 +324,7 @@ guess_structure <- function(xml_node,
...
@@ -324,7 +324,7 @@ guess_structure <- function(xml_node,
wrapper_list
<-
list
()
wrapper_list
<-
list
()
for
(
i
in
seq_
along
(
xml2
::
xml_children
(
xml_node
)))
{
for
(
i
in
seq_
len
(
length
(
(
xml2
::
xml_children
(
xml_node
)))
))
{
child_node
<-
xml2
::
xml_children
(
xml_node
)[[
i
]]
child_node
<-
xml2
::
xml_children
(
xml_node
)[[
i
]]
child_name
<-
xml2
::
xml_name
(
child_node
)
child_name
<-
xml2
::
xml_name
(
child_node
)
...
...
This diff is collapsed.
Click to expand it.
R/sim_utils.R
+
65
−
40
View file @
3ecc6623
...
@@ -32,22 +32,8 @@ run_simulation <- function(ogs6_obj, write_logfile = TRUE) {
...
@@ -32,22 +32,8 @@ run_simulation <- function(ogs6_obj, write_logfile = TRUE) {
}
}
}
}
# Export the simulation files
# Export (and / or copy referenced) simulation files
if
(
!
is.null
(
ogs6_obj
$
gml
)){
export_all_sim_files
(
ogs6_obj
)
export_gml
(
ogs6_obj
$
gml
,
paste0
(
ogs6_obj
$
sim_path
,
basename
(
ogs6_obj
$
geometry
)))
}
else
if
(
!
is.null
(
ogs6_obj
$
geometry
)){
file.copy
(
ogs6_obj
$
geometry
,
ogs6_obj
$
sim_path
)
}
export_prj
(
ogs6_obj
)
# Copy all referenced .vtu files to ogs6_obj$sim_path
lapply
(
ogs6_obj
$
meshes
,
function
(
x
){
file.copy
(
x
,
ogs6_obj
$
sim_path
)
})
# Copy referenced ...
# Construct the call
# Construct the call
ogs6_command_str
<-
paste0
(
ogs6_obj
$
ogs_bin_path
,
"ogs.exe"
)
ogs6_command_str
<-
paste0
(
ogs6_obj
$
ogs_bin_path
,
"ogs.exe"
)
...
@@ -74,6 +60,8 @@ run_simulation <- function(ogs6_obj, write_logfile = TRUE) {
...
@@ -74,6 +60,8 @@ run_simulation <- function(ogs6_obj, write_logfile = TRUE) {
assertthat
::
assert_that
(
!
file.exists
(
ogs6_obj
$
logfile
))
assertthat
::
assert_that
(
!
file.exists
(
ogs6_obj
$
logfile
))
file.create
(
ogs6_obj
$
logfile
)
file.create
(
ogs6_obj
$
logfile
)
cat
(
"\nRunning sim...\n"
)
exit_code
<-
system2
(
command
=
ogs6_command_str
,
exit_code
<-
system2
(
command
=
ogs6_command_str
,
args
=
ogs6_args
,
args
=
ogs6_args
,
stdout
=
ogs6_obj
$
logfile
)
stdout
=
ogs6_obj
$
logfile
)
...
@@ -88,12 +76,45 @@ run_simulation <- function(ogs6_obj, write_logfile = TRUE) {
...
@@ -88,12 +76,45 @@ run_simulation <- function(ogs6_obj, write_logfile = TRUE) {
}
}
#===== Export utility =====
#'export_all_sim_files
#'@description Exports and / or copies all simulation files to
#' `ogs6_obj$sim_path`
#'@param ogs6_obj OGS6: Simulation object
export_all_sim_files
<-
function
(
ogs6_obj
){
assertthat
::
assert_that
(
inherits
(
ogs6_obj
,
"OGS6"
))
if
(
!
is.null
(
ogs6_obj
$
gml
)){
export_gml
(
ogs6_obj
$
gml
,
paste0
(
ogs6_obj
$
sim_path
,
basename
(
ogs6_obj
$
geometry
)))
}
else
if
(
!
is.null
(
ogs6_obj
$
geometry
)){
file.copy
(
ogs6_obj
$
geometry
,
ogs6_obj
$
sim_path
)
}
# Copy all referenced .vtu files to ogs6_obj$sim_path
lapply
(
ogs6_obj
$
meshes
,
function
(
x
){
file.copy
(
x
,
ogs6_obj
$
sim_path
)
})
if
(
!
is.null
(
ogs6_obj
$
python_script
)){
file.copy
(
ogs6_obj
$
python_script
,
ogs6_obj
$
sim_path
)
}
export_prj
(
ogs6_obj
)
return
(
invisible
())
}
#===== Validation utility =====
#===== Validation utility =====
#'validate_all
#'validate_all
#'@description Validates all necessary parameters
#'@description Validates all necessary parameters
#'@param ogs6_obj
A
OGS6
class
object
#'@param ogs6_obj OGS6
: Simulation
object
validate_all
<-
function
(
ogs6_obj
)
{
validate_all
<-
function
(
ogs6_obj
)
{
if
(
!
ogs6_obj
$
get_status
(
print_status
=
FALSE
)){
if
(
!
ogs6_obj
$
get_status
(
print_status
=
FALSE
)){
...
@@ -123,26 +144,26 @@ validate_all <- function(ogs6_obj) {
...
@@ -123,26 +144,26 @@ validate_all <- function(ogs6_obj) {
#'@description Utility function for quick benchmark runs
#'@description Utility function for quick benchmark runs
#'@param prj_path string:
#'@param prj_path string:
#'@param ogs_bin_path string:
#'@param ogs_bin_path string:
#'@param sim_path string: Optional: Path where simulation files will be saved.
#'@param sim_path string: Path where simulation files will be saved.
#' Change this to fit your system!
run_benchmark
<-
function
(
prj_path
,
run_benchmark
<-
function
(
prj_path
,
ogs_bin_path
,
ogs_bin_path
,
sim_path
=
"D:/OGS_all_simulations/"
){
sim_path
){
if
(
missing
(
ogs_bin_path
)){
ogs_bin_path
<-
options
(
"r2ogs6.default_ogs_bin_path"
)
}
if
(
missing
(
ogs_bin_path
)
||
if
(
missing
(
sim_path
)){
!
assertthat
::
is.string
(
ogs_bin_path
)
||
sim_path
<-
options
(
"r2ogs6.default_sim_path"
)
ogs_bin_path
==
""
){
ogs_bin_path
<-
get_default_ogs_bin_path
()
}
}
assertthat
::
assert_that
(
assertthat
::
is.string
(
prj_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
prj_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
ogs_bin_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
sim_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
sim_path
))
sim_path
<-
validate_is_dir_path
(
sim_path
)
sim_path
<-
validate_is_dir_path
(
sim_path
)
sim_name
<-
substr
(
basename
(
prj_path
),
sim_name
<-
tools
::
file_path_sans_ext
(
basename
(
prj_path
))
start
=
0
,
stop
=
nchar
(
basename
(
prj_path
))
-
4
)
sim_subdir_path
<-
paste0
(
sim_path
,
sim_subdir_path
<-
paste0
(
sim_path
,
basename
(
dirname
(
prj_path
)),
basename
(
dirname
(
prj_path
)),
...
@@ -156,7 +177,8 @@ run_benchmark <- function(prj_path,
...
@@ -156,7 +177,8 @@ run_benchmark <- function(prj_path,
read_in_prj
(
ogs6_obj
=
ogs6_obj
,
read_in_prj
(
ogs6_obj
=
ogs6_obj
,
prj_path
=
prj_path
,
prj_path
=
prj_path
,
read_in_vtu
=
FALSE
)
read_in_vtu
=
FALSE
,
read_in_gml
=
TRUE
)
return
(
invisible
(
run_simulation
(
ogs6_obj
)))
return
(
invisible
(
run_simulation
(
ogs6_obj
)))
}
}
...
@@ -168,28 +190,31 @@ run_benchmark <- function(prj_path,
...
@@ -168,28 +190,31 @@ run_benchmark <- function(prj_path,
#'@param path string:
#'@param path string:
#'@param ogs_bin_path string:
#'@param ogs_bin_path string:
#'@param sim_path string:
#'@param sim_path string:
#'@param starting_from_prj_path string:
#'@param starting_from_prj_path string:
.prj path to start from
#'@param print_failed_prj_paths flag:
#'@param print_failed_prj_paths flag:
Output paths where `read_in_prj()` failed?
run_all_benchmarks
<-
function
(
path
,
run_all_benchmarks
<-
function
(
path
,
ogs_bin_path
,
ogs_bin_path
,
sim_path
=
"D:/OGS_all_simulations/"
,
sim_path
,
starting_from_prj_path
=
""
,
starting_from_prj_path
=
""
,
print_failed_prj_paths
=
TRUE
){
print_failed_prj_paths
=
TRUE
){
if
(
missing
(
path
)
||
if
(
missing
(
path
)){
!
assertthat
::
is.string
(
path
)
||
path
<-
options
(
"r2ogs6.default_benchmark_path"
)
path
==
""
){
path
<-
get_default_benchmark_path
()
}
}
if
(
missing
(
ogs_bin_path
)
||
if
(
missing
(
ogs_bin_path
)){
!
assertthat
::
is.string
(
ogs_bin_path
)
||
ogs_bin_path
<-
options
(
"r2ogs6.default_ogs_bin_path"
)
ogs_bin_path
==
""
){
ogs_bin_path
<-
get_default_ogs_bin_path
()
}
}
assertthat
::
assert_that
(
assertthat
::
is.flag
(
print_failed_prj_paths
))
if
(
missing
(
sim_path
)){
sim_path
<-
options
(
"r2ogs6.default_sim_path"
)
}
assertthat
::
assert_that
(
assertthat
::
is.string
(
path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
ogs_bin_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
sim_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
starting_from_prj_path
))
assertthat
::
assert_that
(
assertthat
::
is.string
(
starting_from_prj_path
))
assertthat
::
assert_that
(
assertthat
::
is.flag
(
print_failed_prj_paths
))
prj_paths
<-
list.files
(
path
=
path
,
prj_paths
<-
list.files
(
path
=
path
,
pattern
=
"\\.prj$"
,
pattern
=
"\\.prj$"
,
...
...
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