diff --git a/R/generate_benchmark_script.R b/R/generate_benchmark_script.R index 588dd5d7db5ab024b4f715671d41545a499524f2..adbe432d8fea2c12880fbe4ed1d40ef5851f7186 100644 --- a/R/generate_benchmark_script.R +++ b/R/generate_benchmark_script.R @@ -117,7 +117,8 @@ generate_all_benchmark_scripts <- #' @description Generates a benchmark script from an existing \code{.prj} file. #' @param prj_path string: \code{.prj} file the script will be based on #' @param sim_path string: Path where all simulation files will be saved -#' @param ogs6_bin_path string: OpenGeoSys bin folder path +#' @param ogs6_bin_path string: Path to OpenGeoSys executable. Defaults to +#' options("r2ogs6.default_ogs6_bin_path"). #' @param script_path string: Path where benchmark script will be saved #' @param read_in_gml flag: Optional: Should \code{.gml} file just be copied or #' read in too? diff --git a/R/ogs6_vtu.R b/R/ogs6_vtu.R index 78060dd36e08d7bab22ac4d14faa4b3914274259..9b6f5309d96f90a901e12f1cdf97945fde830110 100644 --- a/R/ogs6_vtu.R +++ b/R/ogs6_vtu.R @@ -334,18 +334,18 @@ validate_coordinates <- function(coordinates){ #' (VTK mesh generator). For full documentation see #' https://www.opengeosys.org/docs/tools/meshing/structured-mesh-generation/ #' @param args_str string: The arguments the script will be called with -#' @param ogs6_bin_path string: Optional: Path to OpenGeoSys6 bin folder. -#' Defaults to options("r2ogs6.default_ogs6_bin_path") +#' @param ogs6_utils_path string: Optional: Path to OpenGeoSys6 utils folder. +#' Defaults to options("r2ogs6.default_ogs6_utils_path") #' @return string: .vtu file path #' @export ogs6_generate_structured_mesh = function(args_str, - ogs6_bin_path) { + ogs6_utils_path) { - if(missing(ogs6_bin_path)){ - ogs6_bin_path <- unlist(options("r2ogs6.default_ogs6_bin_path")) + if(missing(ogs6_utils_path)){ + ogs6_utils_path <- unlist(options("r2ogs6.default_ogs6_utils_path")) } - assertthat::assert_that(assertthat::is.string(ogs6_bin_path)) + assertthat::assert_that(assertthat::is.string(ogs6_utils_path)) assertthat::assert_that(assertthat::is.string(args_str)) @@ -353,7 +353,7 @@ ogs6_generate_structured_mesh = function(args_str, vtu_path <- stringr::str_extract(args_str, "-o [^ ]*") vtu_path <- stringr::str_remove(vtu_path, "-o ") - system(command = paste0(ogs6_bin_path, + system(command = paste0(ogs6_utils_path, "generateStructuredMesh.exe ", args_str)) diff --git a/R/sim_utils.R b/R/sim_utils.R index d39682cd928043be0002f241c8c67d77469bf1ec..5b05e0041327edaf70caf612e525bc2138a7edc6 100644 --- a/R/sim_utils.R +++ b/R/sim_utils.R @@ -9,7 +9,7 @@ #' @param write_logfile flag: Should output be written to a logfile? If #' \code{FALSE}, output will be written to console. If \code{TRUE}, logfile #' directory will be created in \code{ogs6$sim_path} directory -#' @param ogs6_bin_path string: Optional: OpenGeoSys 6 bin folder path. Defaults +#' @param ogs6_bin_path string: Optional: OpenGeoSys 6 executable path. Defaults #' to \code{options("r2ogs6.default_ogs6_bin_path")} #' @param verbose flag #' @export @@ -117,7 +117,8 @@ ogs6_export_sim_files <- function(ogs6_obj, #' @param write_logfile flag: Should output be written to a logfile? If #' \code{FALSE}, output will be written to console. If \code{TRUE}, logfile #' directory will be created in \code{ogs6$sim_path} directory -#' @param ogs6_bin_path string: Optional: OpenGeoSys 6 bin folder path. Defaults +#' @param ogs6_bin_path string: Optional: Path to OpenGeoSys 6 executable or +#' OpenGeoSys container (singularity image) file. Defaults #' to \code{options("r2ogs6.default_ogs6_bin_path")} #' @param verbose flag #' @export @@ -136,16 +137,20 @@ ogs6_call_ogs6 <- function(ogs6_obj, assertthat::assert_that(assertthat::is.string(ogs6_bin_path)) assertthat::assert_that(assertthat::is.flag(verbose)) - # Construct the call - exe_str <- ifelse(Sys.info()["sysname"] == "Windows", - "ogs.exe", - "ogs") - - ogs6_command_str <- paste0(ogs6_bin_path, exe_str) - sim_path_full <- paste0(ogs6_obj$sim_path, + # construt call to os + prj_path_full <- paste0(ogs6_obj$sim_path, ogs6_obj$sim_name, ".prj") - ogs6_args <- c(sim_path_full, "-o", ogs6_obj$sim_path) + ogs6_args <- c(prj_path_full, "-o", ogs6_obj$sim_path) + ogs6_command <- construct_ogs_command(ogs6_bin_path) + + # reorder for using 'system2()' + if (length(ogs6_command)>1) { + ogs6_command_str <- ogs6_command[1] + ogs6_args <- c(ogs6_command[-1], ogs6_args) + } else { + ogs6_command_str <- ogs6_command + } exit_code <- 0 @@ -181,6 +186,44 @@ ogs6_call_ogs6 <- function(ogs6_obj, } + +#' construct_ogs_command +#' @description Constructs the call string to for 'system2()'. +#' @param ogs6_bin_path string: Optional: Path to OpenGeoSys 6 executable or +#' OpenGeoSys container (singularity image) file. Defaults +#' to \code{options("r2ogs6.default_ogs6_bin_path")} +#' +#' @return string: Call object. +construct_ogs_command <- function(ogs6_bin_path){ + + assertthat::assert_that(assertthat::is.string(ogs6_bin_path)) + + # check if existent + if (dir.exists(ogs6_bin_path)) { + stop("'ogs6_bin_path' has to be an executable or container image file.", + call. = FALSE) + } + else if (!(file.exists(ogs6_bin_path))) { + stop("'ogs6_bin_path' does not exist.'", + call. = FALSE) + } + + # Construct the call wether ogs6_bin_path is executable or + # container image file + if (stringr::str_sub(ogs6_bin_path, -4) == ".sif"){ + + assertthat::assert_that(file.exists(ogs6_bin_path)) + ogs6_command <- c("singularity","exec", "--app ogs", + ogs6_bin_path, "ogs") + } + else { + ogs6_command <- paste0(ogs6_bin_path) + assertthat::assert_that(file.exists(ogs6_command)) + } + + return(ogs6_command) +} + #===== ogs6_read_output_files ===== diff --git a/R/zzz.R b/R/zzz.R index 8b70e3c21673b8268d3f21c54144869df99bf9c2..3db11061130c50af8a88e7cb11b3b1a0313356b0 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -13,6 +13,7 @@ vtk <- NULL r2ogs6.default_script_path = "", r2ogs6.default_benchmark_path = "", r2ogs6.default_ogs6_processlib_path = "", + r2ogs6.default_ogs6_utils_path = "", r2ogs6.default_ogs6_bin_path = "", r2ogs6.max_lines_gml = 300, @@ -38,12 +39,18 @@ vtk <- NULL "D:/Programme/OpenGeoSys/ogs-master/Tests/Data/", r2ogs6.default_ogs6_processlib_path = "D:/Programme/OpenGeoSys/ogs-master/ProcessLib/", - r2ogs6.default_ogs6_bin_path = + r2ogs6.default_ogs6_utils_path = paste0( "D:/Programme/OpenGeoSys/", "ogs-6.3.2-Windows-10.0.14393-x64-python-3.7.2-de-utils", "/bin/" ), + r2ogs6.default_ogs6_bin_path = + paste0( + "D:/Programme/OpenGeoSys/", + "ogs-6.3.2-Windows-10.0.14393-x64-python-3.7.2-de-utils", + "/bin/ogs.exe" + ), r2ogs6.max_lines_gml = 300, r2ogs6.use_python = "D:/Programme/anaconda3/envs/rtest/python.exe" )