Commit b6ba3134 authored by Dorchies David's avatar Dorchies David
Browse files

refactor: sic_run_fortran to sic_run_mesh, sic_runsteady and sic_run_unsteady

1 merge request!7Resolve "Generate PAR file for driving simulation"
Pipeline #34077 failed with stage
in 2 minutes and 37 seconds
Showing with 459 additions and 151 deletions
+459 -151
......@@ -6,8 +6,9 @@ S3method(SicInput,matrix)
S3method(SicInput,numeric)
S3method(merge,SicInput)
export(SicInput)
export(SicLocation)
export(SicLocations)
export(cfg_tmp_project)
export(convert_sic_params)
export(create_section_txt)
export(create_uniform_reach_txt)
export(dem_to_reach)
......@@ -23,7 +24,10 @@ export(read_bin_result_matrix)
export(set_initial_conditions)
export(sic_import_reaches)
export(sic_run_export)
export(sic_run_fortran)
export(sic_run_mesh)
export(sic_run_steady)
export(sic_run_unsteady)
export(sic_write_par)
export(split_reach)
import(magrittr)
import(utils)
......
#' Convert a list of parameters into command line arguments for Fortran SIC programs
#'
#' This function is called by [sic_run_fortran] to convert list of parameters into a [character] command line parameters.
#'
#' The parameter `INTERF` is set to 0 (zero) by default.
#'
#' @param params a [list] of [character] containing the parameters to send to the fortran program with format `list(param=value, ...)`
#' @template param_cfg
#'
#' @return A [character] with each parameter is converted to `[key param]=[value param]` and each parameter separated by a space character.
#' @export
#'
#' @examples
#' \dontrun{
#' cfg <- cfg_tmp_project()
#' convert_sic_params(list(SCE = 1, VAR = 1), cfg = cfg)
#' }
convert_sic_params <- function(params, cfg = loadConfig()) {
if (!"INTERF" %in% names(params)) {
params <- c(list(INTERF = cfg$sic$fortran$prms$INTERF), params)
}
params <- sapply(names(params), function(key) {
paste(key, params[[key]], sep= "=")
})
paste(params, collapse = " ")
}
#' Get a selection of variables from a simulation result
#'
#' @inheritParams sic_run_export
#' @inheritParams sic_run_mesh
#' @param filters [character] conditions to select columns in result table, see details
#' @param m [matrix] of results produced by [read_bin_result_matrix]
#'
......@@ -11,7 +11,7 @@
#' @examples
#' \dontrun{
#' cfg <- cfg_tmp_project()
#' sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg)
#' sic_run_steady(cfg, scenario = 1)
#' get_result(cfg, 1, filters = c("bf==4", "var=='Z'"))
#' }
get_result <- function(cfg,
......@@ -47,7 +47,7 @@ get_result <- function(cfg,
#' Read matrix of SIC simulation result file
#'
#' @inheritParams sic_run_export
#' @inheritParams sic_run_mesh
#'
#' @return [matrix] with the simulation results
#' @export
......@@ -55,7 +55,7 @@ get_result <- function(cfg,
#' @examples
#' \dontrun{
#' cfg <- cfg_tmp_project()
#' sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg)
#' sic_run_steady(cfg, scenario = 1)
#' m <- read_bin_result_matrix(cfg, 1)
#' str(m)
#' }
......@@ -90,7 +90,7 @@ read_bin_result_matrix <- function(cfg, scenario, variant = 0) {
#' Get correspondence between network object and columns in result binary file
#'
#' @inheritParams sic_run_export
#' @inheritParams sic_run_mesh
#'
#' @return a [data.frame] with following columns:
#'
......@@ -98,7 +98,7 @@ read_bin_result_matrix <- function(cfg, scenario, variant = 0) {
#' - "var": the name of the calculated variable
#' - "col": the column number in the matrix produced by [read_bin_result_matrix]
#'
#' @warning
#' @section Warning:
#' Up to now, this function only handle results at sections.
#'
#' @export
......@@ -108,7 +108,7 @@ read_bin_result_matrix <- function(cfg, scenario, variant = 0) {
#' @examples
#' \dontrun{
#' cfg <- cfg_tmp_project()
#' sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg)
#' sic_run_steady(cfg, scenario = 1)
#' df <- get_result_tree(cfg, 1)
#' head(df)
#' }
......
......@@ -2,30 +2,25 @@
#'
#' Import initial conditions from a scenario/variant result calculation to a new scenario/variant.
#'
#' @param params [numeric], arguments passed to Edisic for importing initial conditions. See details
#' @param iniParams [numeric], arguments passed to Edisic for importing initial conditions. See details
#' @template param_cfg
#'
#' @details `params` [numeric] vector of length 5. Each number correspond to:
#' @details `iniParams` [numeric] vector of length 5. Each number correspond to:
#'
#' 1. number of the scenario from which import initial conditions
#' 1. number of the variant from which import initial conditions (Use "0" for no variant)
#' 1. Time in seconds of the initial conditions to import (Use "0" for a single permanent simulation with no time steps)
#' 1. number of the scenario where the initial conditions are exported to
#' 1. number of the variant where the initial conditions are exported to (Use "0" for no variant)
#' 2. number of the variant from which import initial conditions (Use "0" for no variant)
#' 3. Time in seconds of the initial conditions to import (Use "0" for a single permanent simulation with no time steps)
#' 4. number of the scenario where the initial conditions are exported to
#' 5. number of the variant where the initial conditions are exported to (Use "0" for no variant)
#'
#' @export
#'
#' @examples
#' \dontrun{
#' # Import initial conditions from the scenario #1 without variant at time 0s
#' # to the variant #1 in the scenario #1
#' set_initial_conditions(c(1, 0, 0, 1, 1))
#' }
set_initial_conditions <- function(params, cfg = loadConfig()) {
if (!is.numeric(params) || length(params) != 5) {
stop("`params` should be a numeric of length 5")
#' @inherit sic_run_mesh return examples
set_initial_conditions <- function(iniParams, cfg = loadConfig()) {
if (!is.numeric(iniParams) || length(iniParams) != 5) {
stop("`iniParams` should be a numeric of length 5")
}
sArgs <- paste(params, collapse = " ")
sArgs <- paste(iniParams, collapse = " ")
cmd_line <- shQuote(
paste(
file.path(cfg$sic$path, cfg$sic$edisic),
......
......@@ -14,14 +14,28 @@ sic_get_par_filename <- function(cfg, scenario) {
#' Write a PAR file for SIC simulation
#'
#' Write inputs in a PAR file respectively to \link{https://sic.g-eau.fr/Format-of-the-par-file}
#' Write inputs in a PAR file respectively to \url{https://sic.g-eau.fr/Format-of-the-par-file}.
#'
#' @inheritParams sic_run_fortran
#' @inheritParams sic_run_mesh
#'
#' @return Nothing.
#' @export
#'
#' @examples
#' \dontrun{
#' # Setting the model configuration
#' cfg <- cfg_tmp_project()
#'
#' # How to impose an hydrograph at the upstream offtake of the model?
#' # Define the location of the upstream boundary condition to set
#' locations <- SicLocations(list(Nd = 1, Pr = 1, car = "Q"))
#' # Define its time series
#' sicInputs <- SicInput(data.frame(t = c(0, 3600, 7200), # time in seconds
#' v = c(5, 20, 5)), # flows
#' locations = locations)
#' # Write the parameters in the PAR file
#' sic_write_par(cfg, 1, sicInputs)
#' }
sic_write_par <- function(cfg, scenario, sicInputs) {
if (is.null(attr(cfg, "config"))) {
......@@ -77,9 +91,20 @@ sic_write_par <- function(cfg, scenario, sicInputs) {
#' - `interpolated`: [logical], interpolation mode
#'
#' @rdname SicInput
#' @family SicInput
#' @export
#'
#' @examples
#' # How to impose 5 m3/s in the upstream offtake of the model?
#' # Define location of the boundary condition to set
#' locations <- SicLocations(list(Nd = 1, Pr = 1, car = "Q"))
#' # Define its value
#' sicInputs <- SicInput(5, locations = locations)
#'
#' # How to impose an hydrograph at the upstream offtake of the model?
#' sicInputs <- SicInput(data.frame(t = c(0, 3600, 7200), # time in seconds
#' v = c(5, 20, 5)), # flows
#' locations = locations)
SicInput <- function(x, ...) {
UseMethod("SicInput", x)
}
......@@ -139,14 +164,33 @@ SicInput.matrix <- function(x, ...) {
#' Merge SicInput objects into a list
#'
#' @param x
#' @param y
#' @param ...
#' @param x a [SicInput] object to merge
#' @param y a [SicInput] object to merge
#' @param ... other [SicInput] objects to merge
#'
#' @details The list of parameter is compliant with the `merge` S3 method
#' available in R, so this method can either be called by typing
#' `merge` or `merge.SicInput`.
#'
#' @return A `SicInputs` object which is a list of [SicInput]
#' @export
#'
#' @examples
#' # How to impose 5 m3/s in the upstream offtake of the model?
#' # Define location of the boundary condition to set
#' locations <- SicLocation(list(Nd = 1, Pr = 1, car = "Q"))
#' # Define its value
#' sicInputUpstream <- SicInput(5, locations = locations)
#'
#' # Opening a gate at 0.5 m
#' sicInputGate <- SicInput(
#' 0.5,
#' locations = SicLocations(list(Bf = 3, Sn = 2, Ouv = 1, Car = "Ouverture"))
#' )
#'
#' # Merging all inputs
#' sicInputs <- merge(sicInputUpstream, sicInputGate)
#'
merge.SicInput <- function(x, y = NULL, ...) {
sicInputs <- list(x, y, ...)
sicInputs[sapply(sicInputs, is.null)] <- NULL
......@@ -154,15 +198,43 @@ merge.SicInput <- function(x, y = NULL, ...) {
return(sicInputs)
}
#' Set locations of a SIC model input
#'
#' Do the same as [SicLocation] for eventually several locations
#'
#' @param ... One or several [list] describing a location (See [SicLocation])
#'
#' @return a *SicLocations* object which is a [list] of [SicLocation].
#' @family SicInput
#' @export
#'
#' @examples
#' # Applying the same flow to offtakes located in nodes number 1 to 10
#' locations <- lapply(seq(10), function(i) { list(Nd = i, Pr = 1, Car = "Q")})
#' locations <- do.call(SicLocations, locations)
#' sicInputOfftakes <- SicInput(-0.5, locations = locations)
SicLocations <- function(...) {
locations <- list(...)
if (length(locations) == 1) locations <- locations[[1]]
# Handle a single location in the parameters
if (length(locations[[1]]) == 1) locations <- list(locations)
if(!is.list(locations)) stop("`locations` must be a list")
l <- sapply(locations, SicLocation)
class(l) <- c("SicLocations", class(l))
return(l)
}
#' Set a location of a SIC model input
#'
#' @param location a [list] containing the location keys (see details)
#'
#' @return a *SicLocation* object which is a [character] string in the same format as the locations described in the sic documentation of PAR files: \url{https://sic.g-eau.fr/Format-of-the-par-file}.
#'
#' @family SicInput
#' @export
#'
#' @inherit SicInput return examples
#'
SicLocation <- function(location) {
names(location) <- toupper(names(location))
# Checks
......
......@@ -2,9 +2,7 @@
#'
#' @details
#' `params` parameter is a list representing parameters available in \url{https://sic.g-eau.fr/sicexport-utilitaire-d-exportation} to set the model network location of exported results. The string parameter `/x=n /yy=ii` in the command line is here represented by `list(xxx = nnn, yy = ii)`.
#'
#' @param scenario [numeric], the scenario to read
#' @param variant [numeric], the variant to read
#' @inheritParams sic_run_mesh
#' @param params [list] location parameters of the result, see details.
#' @template param_cfg
#'
......@@ -14,7 +12,7 @@
#' @examples
#' \dontrun{
#' params <- list(SCE=1)
#' sic_run_fortran("fluvia", params)
#' sic_run_steady(cfg, scenario = 1)
#' # For exporting result in sections at time 0
#' sic_run_export(scenario = 1, params = list(t = 0))
#' }
......
#' Run Talweg, Fluvia or Sirene
#' Run Talweg, Fluvia or Sirene for a configured project
#'
#' @param prog [character], the program to run. Should be one of "talweg"
#' Use `sic_run_mesh` to run the mesh generator, `sic_run_steady` for steady flow
#' simulation, and `sic_run_unsteady` for unsteady flow simulation.
#'
#' @param scenario [numeric], the scenario to use
#' @param variant [numeric], the variant to use (0 by default means no variant)
#' @param params [list] or [character], see details
#' @param sicInputs A [SicInput] object or a list of [SicInput] objects create by [merge.SicInput]
#' used to create a PAR file injectig inputs for the simulation
#' @param iniParams 5-length [numeric] [vector], see [set_initial_conditions] for details
#' @template param_cfg
#'
#' @details If argument `params` is a [list], arguments are injected in the command line by taking the items of the list with the conversion
#' `[key]=[value]`. If argument `params` is a [character]
#' @details The argument `params` handles the parameters describe in
#' [SIC documentation](https://sic.g-eau.fr/Execution-de-TALWEG-FLUVIA-et).
#' If argument `params` is a [list], arguments are injected in the command line
#' by taking the items of the list with the conversion `[key]=[value]`.
#' By default, the parameter `INTERF=0` is added to the command line.
#' If argument `params` is a [character] string it is directly used as parameters of the command line.
#'
#' @return Error code returned by [shell].
#' @export
#'
#' @examples
#' \dontrun{
#' # Set up the configuration model
#' cfg <- cfg_tmp_project()
#'
#' # Generate the mesh of the model
#' sic_run_mesh(cfg)
#'
#' # Run steady simulation for the scenario #1
#' sic_run_steady(cfg, scenario = 1)
#'
#' # Import initial condition from scenario 1
#' # to scenario 1, variant 1 for unsteady flow simulation
#' set_initial_conditions(c(1, 0, 0, 1, 1), cfg = cfg)
#'
#' # Run unsteady flow simulation
#' sic_run_unsteady(cfg, scenario = 1, variant = 1)
#'
#' # Or initiate and run the same unsteady flow simulation in one call
#' sic_run_unsteady(cfg, iniParams = c(1, 0, 0, 1, 1))
#' }
sic_run_mesh <- function(cfg, params = list()) {
sic_run_fortran(cfg, "talweg", params)
}
#' Convert a list of parameters into command line arguments for Fortran SIC programs
#'
#' This function is called by [sic_run_fortran] to convert list of parameters into a [character] command line parameters.
#'
#' The parameter `INTERF` is set to 0 (zero) by default.
#'
#' @param params a [list] of [character] containing the parameters to send to the fortran program with format `list(param=value, ...)`
#' @template param_cfg
#'
#' @return A [character] with each parameter is converted to `[key param]=[value param]` and each parameter separated by a space character.
#' @noRd
#'
#' @examples
#' \dontrun{
#' cfg <- cfg_tmp_project()
#' params <- list(SCE=1)
#' sic_run_fortran("fluvia", params, cfg = cfg)
#'}
sic_run_fortran <- function(prog, params = list(), cfg = loadConfig()) {
#' convert_sic_params(list(SCE = 1, VAR = 1), cfg = cfg)
#' }
convert_sic_params <- function(params, cfg = loadConfig()) {
if (!"INTERF" %in% names(params)) {
params <- c(list(INTERF = cfg$sic$fortran$prms$INTERF), params)
}
params <- sapply(names(params), function(key) {
paste(key, params[[key]], sep= "=")
})
paste(params, collapse = " ")
}
#' @param prog [character], the program to run. Should be one of "talweg"
#' @noRd
sic_run_fortran <- function(cfg, prog, params) {
if (is.list(params)) params <- convert_sic_params(params, cfg)
cmd_line <- shQuote(
paste(
......@@ -28,11 +86,36 @@ sic_run_fortran <- function(prog, params = list(), cfg = loadConfig()) {
type = "cmd2"
)
logger::log_debug(cmd_line)
ret <- shell(
shell(
cmd_line,
wait = T,
translate = T
)
file.remove("FLUVIA.INI", "SIRENE.INI")
return(ret)
}
#' @noRd
sic_run_simulation <- function(cfg, prog, scenario, variant, sicInputs, params) {
if (!is.null(sicInputs)) {
sic_write_par(cfg, scenario, sicInputs)
}
params <- c(list(SCE = scenario, VAR = variant), params)
sic_run_fortran(cfg, prog, params)
}
#' @rdname sic_run_mesh
#' @export
sic_run_steady <- function(cfg, scenario, variant = 0, sicInputs = NULL, params = list()) {
sic_run_simulation(cfg, "fluvia", scenario, variant, sicInputs, params)
}
#' @rdname sic_run_mesh
#' @export
sic_run_unsteady <- function(cfg, scenario = iniParams[4], variant = iniParams[5], sicInputs = NULL, iniParams = NULL, params = list()) {
if (!is.null(iniParams)) {
sic_run_steady(cfg, scenario = iniParams[1], variant = iniParams[1])
set_initial_conditions(iniParams, cfg)
}
if (is.null(scenario)) stop("`scenario` should be defined")
if (is.null(variant)) variant <- 0
sic_run_simulation(cfg, "sirene", scenario, variant, sicInputs, params)
}
......@@ -7,6 +7,21 @@
#' @export
#'
#' @examples
#' # Create a 10km long trapezoidal uniform reach
#' profT <- list(
#' B = 2,
#' S = (6 - 2) / 2 / 2,
#' ZF = 100,
#' ZB = 100 + 2
#' )
#' min_reach <- create_uniform_reach_txt(abscissas = seq(0, 10000, 100),
#' upstream_bed_elevation = 10 + 2000 * 0.002,
#' slope = 0.002,
#' section_type = "T",
#' profile = profT)
#' # Split into reaches of 2000 m
#' reaches <- split_reach(min_reach, seq(0, 10000, 2000))
#'
split_reach <- function(reach, x_limits) {
if(length(x_limits) < 2) {
stop("`x_limits` length must be greater or equal to 2")
......@@ -16,6 +31,8 @@ split_reach <- function(reach, x_limits) {
#' Select portion of a reach between two chainages
#'
#' This function is used by [split_reach] for selecting sections of each reach.
#'
#' @param reach A ReachTxt object
#' @param x_limits 2-length [numeric], min and max chainage
#'
......@@ -23,6 +40,21 @@ split_reach <- function(reach, x_limits) {
#' @export
#'
#' @examples
#' # Create a 10km long trapezoidal uniform reach
#' profT <- list(
#' B = 2,
#' S = (6 - 2) / 2 / 2,
#' ZF = 100,
#' ZB = 100 + 2
#' )
#' min_reach <- create_uniform_reach_txt(abscissas = seq(0, 10000, 100),
#' upstream_bed_elevation = 10 + 2000 * 0.002,
#' slope = 0.002,
#' section_type = "T",
#' profile = profT)
#' # Extract sections between chainage 2000 m and 4000 m
#' sel_reach <- extract_reach(min_reach, c(2000, 4000))
#'
extract_reach <- function(reach, x_limits) {
reach_names <- names(reach)
x_limits <- sprintf("%08d", x_limits)
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sic_inputs.R
\name{SicInput}
\alias{SicInput}
\alias{SicInput.numeric}
\alias{SicInput.POSIXt}
\alias{SicInput.data.frame}
\alias{SicInput.matrix}
\title{Create a SIC input for a PAR file}
\usage{
SicInput(x, ...)
\method{SicInput}{numeric}(x, values = NULL, locations, interpolated = TRUE, ...)
\method{SicInput}{POSIXt}(x, values, start = NULL, ...)
\method{SicInput}{data.frame}(x, ...)
\method{SicInput}{matrix}(x, ...)
}
\arguments{
\item{x}{either a fixed input, a \link{numeric} vector of time in seconds,
a \link{POSIXt} vector of time, a \link{matrix} or a \link{data.frame} with 2 columns (time and value)}
\item{...}{used for S3 method compatibility}
\item{values}{a \link{numeric} vector used if \code{x} is a vector of \link{numeric} or \link{POSIXt}}
\item{locations}{input locations created with \link{SicLocation} or \link{SicLocations}}
\item{interpolated}{Interpolation mode \code{TRUE} for "ramp" mode and \code{FALSE} for "step" mode}
\item{start}{a \link{POSIXt} indicating the start time to use as time zero in the simulation}
}
\value{
A \emph{SicInput} object which is a list with the following items:
\itemize{
\item \code{locations}: a \link{SicLocations} object
\item \code{data}: \link{numeric}, the fixed value, or \link{data.frame}, the time series to apply to the locations
\item \code{interpolated}: \link{logical}, interpolation mode
}
}
\description{
Create a SIC input for a PAR file
}
\examples{
# How to impose 5 m3/s in the upstream offtake of the model?
# Define location of the boundary condition to set
locations <- SicLocations(list(Nd = 1, Pr = 1, car = "Q"))
# Define its value
sicInputs <- SicInput(5, locations = locations)
# How to impose an hydrograph at the upstream offtake of the model?
sicInputs <- SicInput(data.frame(t = c(0, 3600, 7200), # time in seconds
v = c(5, 20, 5)), # flows
locations = locations)
}
\seealso{
Other SicInput:
\code{\link{SicLocations}()},
\code{\link{SicLocation}()}
}
\concept{SicInput}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sic_inputs.R
\name{SicLocation}
\alias{SicLocation}
\title{Set a location of a SIC model input}
\usage{
SicLocation(location)
}
\arguments{
\item{location}{a \link{list} containing the location keys (see details)}
}
\value{
a \emph{SicLocation} object which is a \link{character} string in the same format as the locations described in the sic documentation of PAR files: \url{https://sic.g-eau.fr/Format-of-the-par-file}.
}
\description{
Set a location of a SIC model input
}
\examples{
# How to impose 5 m3/s in the upstream offtake of the model?
# Define location of the boundary condition to set
locations <- SicLocations(list(Nd = 1, Pr = 1, car = "Q"))
# Define its value
sicInputs <- SicInput(5, locations = locations)
# How to impose an hydrograph at the upstream offtake of the model?
sicInputs <- SicInput(data.frame(t = c(0, 3600, 7200), # time in seconds
v = c(5, 20, 5)), # flows
locations = locations)
}
\seealso{
Other SicInput:
\code{\link{SicInput}()},
\code{\link{SicLocations}()}
}
\concept{SicInput}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sic_inputs.R
\name{SicLocations}
\alias{SicLocations}
\title{Set locations of a SIC model input}
\usage{
SicLocations(...)
}
\arguments{
\item{...}{One or several \link{list} describing a location (See \link{SicLocation})}
}
\value{
a \emph{SicLocations} object which is a \link{list} of \link{SicLocation}.
}
\description{
Do the same as \link{SicLocation} for eventually several locations
}
\examples{
# Applying the same flow to offtakes located in nodes number 1 to 10
locations <- lapply(seq(10), function(i) { list(Nd = i, Pr = 1, Car = "Q")})
locations <- do.call(SicLocations, locations)
sicInputOfftakes <- SicInput(-0.5, locations = locations)
}
\seealso{
Other SicInput:
\code{\link{SicInput}()},
\code{\link{SicLocation}()}
}
\concept{SicInput}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/convert_sic_params.R
\name{convert_sic_params}
\alias{convert_sic_params}
\title{Convert a list of parameters into command line arguments for Fortran SIC programs}
\usage{
convert_sic_params(params, cfg = loadConfig())
}
\arguments{
\item{params}{a \link{list} of \link{character} containing the parameters to send to the fortran program with format \code{list(param=value, ...)}}
\item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details}
}
\value{
A \link{character} with each parameter is converted to \verb{[key param]=[value param]} and each parameter separated by a space character.
}
\description{
This function is called by \link{sic_run_fortran} to convert list of parameters into a \link{character} command line parameters.
}
\details{
The parameter \code{INTERF} is set to 0 (zero) by default.
}
\examples{
\dontrun{
cfg <- cfg_tmp_project()
convert_sic_params(list(SCE = 1, VAR = 1), cfg = cfg)
}
}
......@@ -15,5 +15,22 @@ extract_reach(reach, x_limits)
A ReachTxt object containing the selected sections.
}
\description{
Select portion of a reach between two chainages
This function is used by \link{split_reach} for selecting sections of each reach.
}
\examples{
# Create a 10km long trapezoidal uniform reach
profT <- list(
B = 2,
S = (6 - 2) / 2 / 2,
ZF = 100,
ZB = 100 + 2
)
min_reach <- create_uniform_reach_txt(abscissas = seq(0, 10000, 100),
upstream_bed_elevation = 10 + 2000 * 0.002,
slope = 0.002,
section_type = "T",
profile = profT)
# Extract sections between chainage 2000 m and 4000 m
sel_reach <- extract_reach(min_reach, c(2000, 4000))
}
......@@ -15,9 +15,9 @@ get_result(
\arguments{
\item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details}
\item{scenario}{\link{numeric}, the scenario to read}
\item{scenario}{\link{numeric}, the scenario to use}
\item{variant}{\link{numeric}, the variant to read}
\item{variant}{\link{numeric}, the variant to use (0 by default means no variant)}
\item{filters}{\link{character} conditions to select columns in result table, see details}
......@@ -32,7 +32,7 @@ Get a selection of variables from a simulation result
\examples{
\dontrun{
cfg <- cfg_tmp_project()
sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg)
sic_run_steady(cfg, scenario = 1)
get_result(cfg, 1, filters = c("bf==4", "var=='Z'"))
}
}
......@@ -9,9 +9,9 @@ get_result_tree(cfg, scenario, variant = 0)
\arguments{
\item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details}
\item{scenario}{\link{numeric}, the scenario to read}
\item{scenario}{\link{numeric}, the scenario to use}
\item{variant}{\link{numeric}, the variant to read}
\item{variant}{\link{numeric}, the variant to use (0 by default means no variant)}
}
\value{
a \link{data.frame} with following columns:
......@@ -24,10 +24,15 @@ a \link{data.frame} with following columns:
\description{
Get correspondence between network object and columns in result binary file
}
\section{Warning}{
Up to now, this function only handle results at sections.
}
\examples{
\dontrun{
cfg <- cfg_tmp_project()
sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg)
sic_run_steady(cfg, scenario = 1)
df <- get_result_tree(cfg, 1)
head(df)
}
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sic_inputs.R
\name{merge.SicInput}
\alias{merge.SicInput}
\title{Merge SicInput objects into a list}
\usage{
\method{merge}{SicInput}(x, y = NULL, ...)
}
\arguments{
\item{x}{a \link{SicInput} object to merge}
\item{y}{a \link{SicInput} object to merge}
\item{...}{other \link{SicInput} objects to merge}
}
\value{
A \code{SicInputs} object which is a list of \link{SicInput}
}
\description{
Merge SicInput objects into a list
}
\details{
The list of parameter is compliant with the \code{merge} S3 method
available in R, so this method can either be called by typing
\code{merge} or \code{merge.SicInput}.
}
\examples{
# How to impose 5 m3/s in the upstream offtake of the model?
# Define location of the boundary condition to set
locations <- SicLocation(list(Nd = 1, Pr = 1, car = "Q"))
# Define its value
sicInputUpstream <- SicInput(5, locations = locations)
# Opening a gate at 0.5 m
sicInputGate <- SicInput(
0.5,
locations = SicLocations(list(Bf = 3, Sn = 2, Ouv = 1, Car = "Ouverture"))
)
# Merging all inputs
sicInputs <- merge(sicInputUpstream, sicInputGate)
}
......@@ -9,9 +9,9 @@ read_bin_result_matrix(cfg, scenario, variant = 0)
\arguments{
\item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details}
\item{scenario}{\link{numeric}, the scenario to read}
\item{scenario}{\link{numeric}, the scenario to use}
\item{variant}{\link{numeric}, the variant to read}
\item{variant}{\link{numeric}, the variant to use (0 by default means no variant)}
}
\value{
\link{matrix} with the simulation results
......@@ -22,7 +22,7 @@ Read matrix of SIC simulation result file
\examples{
\dontrun{
cfg <- cfg_tmp_project()
sic_run_fortran("fluvia", list(SCE = 1), cfg = cfg)
sic_run_steady(cfg, scenario = 1)
m <- read_bin_result_matrix(cfg, 1)
str(m)
}
......
......@@ -4,18 +4,21 @@
\alias{set_initial_conditions}
\title{Import initial conditions}
\usage{
set_initial_conditions(params, cfg = loadConfig())
set_initial_conditions(iniParams, cfg = loadConfig())
}
\arguments{
\item{params}{\link{numeric}, arguments passed to Edisic for importing initial conditions. See details}
\item{iniParams}{\link{numeric}, arguments passed to Edisic for importing initial conditions. See details}
\item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details}
}
\value{
Error code returned by \link{shell}.
}
\description{
Import initial conditions from a scenario/variant result calculation to a new scenario/variant.
}
\details{
\code{params} \link{numeric} vector of length 5. Each number correspond to:
\code{iniParams} \link{numeric} vector of length 5. Each number correspond to:
\enumerate{
\item number of the scenario from which import initial conditions
\item number of the variant from which import initial conditions (Use "0" for no variant)
......@@ -26,8 +29,23 @@ Import initial conditions from a scenario/variant result calculation to a new sc
}
\examples{
\dontrun{
# Import initial conditions from the scenario #1 without variant at time 0s
# to the variant #1 in the scenario #1
set_initial_conditions(c(1, 0, 0, 1, 1))
# Set up the configuration model
cfg <- cfg_tmp_project()
# Generate the mesh of the model
sic_run_mesh(cfg)
# Run steady simulation for the scenario #1
sic_run_steady(cfg, scenario = 1)
# Import initial condition from scenario 1
# to scenario 1, variant 1 for unsteady flow simulation
set_initial_conditions(c(1, 0, 0, 1, 1), cfg = cfg)
# Run unsteady flow simulation
sic_run_unsteady(cfg, scenario = 1, variant = 1)
# Or initiate and run the same unsteady flow simulation in one call
sic_run_unsteady(cfg, iniParams = c(1, 0, 0, 1, 1))
}
}
......@@ -7,9 +7,9 @@
sic_run_export(scenario, variant = 0, params, cfg = loadConfig())
}
\arguments{
\item{scenario}{\link{numeric}, the scenario to read}
\item{scenario}{\link{numeric}, the scenario to use}
\item{variant}{\link{numeric}, the variant to read}
\item{variant}{\link{numeric}, the variant to use (0 by default means no variant)}
\item{params}{\link{list} location parameters of the result, see details.}
......@@ -27,7 +27,7 @@ Run SicExport and read the exported file
\examples{
\dontrun{
params <- list(SCE=1)
sic_run_fortran("fluvia", params)
sic_run_steady(cfg, scenario = 1)
# For exporting result in sections at time 0
sic_run_export(scenario = 1, params = list(t = 0))
}
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sic_run_fortran.R
\name{sic_run_fortran}
\alias{sic_run_fortran}
\title{Run Talweg, Fluvia or Sirene}
\usage{
sic_run_fortran(prog, params = list(), cfg = loadConfig())
}
\arguments{
\item{prog}{\link{character}, the program to run. Should be one of "talweg"}
\item{params}{\link{list} or \link{character}, see details}
\item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details}
}
\value{
Error code returned by \link{shell}.
}
\description{
Run Talweg, Fluvia or Sirene
}
\details{
If argument \code{params} is a \link{list}, arguments are injected in the command line by taking the items of the list with the conversion
\verb{[key]=[value]}. If argument \code{params} is a \link{character}
}
\examples{
\dontrun{
# Run steady simulation for the scenario #1
cfg <- cfg_tmp_project()
params <- list(SCE=1)
sic_run_fortran("fluvia", params, cfg = cfg)
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment