diff --git a/NAMESPACE b/NAMESPACE index 52615129209664fa3ab71063afc17af3fc962a62..f92b891b43a4b45ae97ce3d43fb2319299bb0eae 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,6 +21,7 @@ export(get_section_centers) export(loadConfig) export(merge_reaches) export(read_bin_result_matrix) +export(set_boundary_ZQ) export(set_initial_conditions) export(sic_import_reaches) export(sic_run_export) diff --git a/R/set_boundary_ZQ.R b/R/set_boundary_ZQ.R new file mode 100644 index 0000000000000000000000000000000000000000..6f3b37776fbc4eb4cbe9c403f958f7250c23a3ab --- /dev/null +++ b/R/set_boundary_ZQ.R @@ -0,0 +1,31 @@ +#' Set stage-discharge curve at an offtake of the model +#' +#' @description +#' Update the existing stage-discharge boundary condition. +#' +#' @inheritParams sic_run_mesh +#' @param nd [numeric], node number in SIC model +#' @param pr [numeric], offtake number in the node +#' @param mZQ [matrix], stage-discharge relation with first column the water elevation in meters +#' and the second column the discharge in cubic meters per seconds +#' +#' @return This function is only used for side effect on the XML file of the SIC project. +#' @export +#' +#' @examples +#' \dontrun{ +#' cfg <- cfg_tmp_project() +#' z <- seq(5, 20, 1) +#' Q <- (z-5)^1.5 +#' set_boundary_ZQ(cfg, scenario = 1, nd = 3, mZQ = matrix(c(z, Q), ncol = 2)) +#' } +set_boundary_ZQ <- function(cfg, scenario, nd, pr = 1, mZQ) { + x <- read_xml(cfg$project$path) + xPath <- "/Reseau/Liste_Noeuds/Noeud[@Num=%d]/Flu[@nScenario=%d]/Prise[@Num=%d]/ConditionLim/TLoi" + xPath <- sprintf(xPath, nd, scenario, pr) + sZQ <- capture.output(write.table(t(mZQ), sep = "\t", quote = FALSE, col.names = FALSE, row.names = FALSE)) + sZQ <- paste(sZQ, collapse = "\n") + xLoi <- x %>% xml_find_first(xPath) + xml_text(xLoi) <- sZQ + write_xml(x, cfg$project$path) +} diff --git a/man/set_boundary_ZQ.Rd b/man/set_boundary_ZQ.Rd new file mode 100644 index 0000000000000000000000000000000000000000..2f1657b7810941dc38a0bd64ccbd9ac193132ad7 --- /dev/null +++ b/man/set_boundary_ZQ.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/set_boundary_ZQ.R +\name{set_boundary_ZQ} +\alias{set_boundary_ZQ} +\title{Set stage-discharge curve at an offtake of the model} +\usage{ +set_boundary_ZQ(cfg, scenario, nd, pr = 1, mZQ) +} +\arguments{ +\item{cfg}{a \link{config} object. Configuration to use. See \link{loadConfig} for details} + +\item{scenario}{\link{numeric}, the scenario to use} + +\item{nd}{\link{numeric}, node number in SIC model} + +\item{pr}{\link{numeric}, offtake number in the node} + +\item{mZQ}{\link{matrix}, stage-discharge relation with first column the water elevation in meters +and the second column the discharge in cubic meters per seconds} +} +\value{ +This function is only used for side effect on the XML file of the SIC project. +} +\description{ +Update the existing stage-discharge boundary condition. +} +\examples{ +\dontrun{ +cfg <- cfg_tmp_project() +z <- seq(5, 20, 1) +Q <- (z-5)^1.5 +set_boundary_ZQ(cfg, scenario = 1, nd = 3, mZQ = matrix(c(z, Q), ncol = 2)) +} +}