Package 'kwb.hydrus1d'

Title: R Interface for the Last Official Release of Hydrus1D (V4.17.0140) for Windows
Description: R Interface for the Last Official Release of Hydrus1D (v4.17.0140) for Windows.
Authors: Michael Rustler [aut, cre] , Hauke Sonnenberg [ctb] , FlexTreat [fnd], Kompetenzzentrum Wasser Berlin gGmbH (KWB) [cph]
Maintainer: Michael Rustler <[email protected]>
License: MIT + file LICENSE
Version: 0.0.0.9000
Built: 2024-11-08 02:56:50 UTC
Source: https://github.com/KWB-R/kwb.hydrus1d

Help Index


Check HYDRUS Executable and download if needed

Description

Check HYDRUS Executable and download if needed

Usage

check_hydrus_exe(
  dir = file.path(system.file(package = "kwb.hydrus1d"), "extdata/hydrus1d"),
  skip_preinstalled = FALSE
)

Arguments

dir

target directory (default: file.path(system.file(package = "kwb.hydrus1d"), "extdata/hydrus1d"), in case compliant HYDRUS1D version is not available, executable will be downloaded from https://github.com/mrustl/hydrus1d/archive/refs/tags/v4.17.0140.zip

skip_preinstalled

if TRUE checking of preinstalled HYDRUS-1D will be skipped and executable will be downloaded, otherwise not (the default)

Value

path to preinstalled HYDRUS-1D executable (if compliant and parameter skip_preinstalled == FALSE), otherwise path to downloaded HYDRUS-1D

Examples

check_hydrus_exe(skip_preinstalled = FALSE)
check_hydrus_exe(skip_preinstalled = TRUE)

Defaults for Atmosphere

Description

Defaults for Atmosphere

Usage

defaults_atmosphere(
  Prec = 0L,
  rSoil = 0L,
  rRoot = 0L,
  hCritA = 100000L,
  rB = 0L,
  hB = 0L,
  ht = 0L,
  tTop = 0L,
  tBot = 0L,
  Ampl = 0L,
  cTop = 0L,
  cBot = 0L,
  RootDepth = 0L
)

Arguments

Prec

Precipitation (default: 0)

rSoil

Evaporation (default: 0)

rRoot

Transpiration (default: 0)

hCritA

(default: 100000)

rB

rB (default: 0)

hB

hB (default: 0)

ht

ht (default: 0)

tTop

tTop (default: 0)

tBot

tBot (default: 0)

Ampl

Ampl (default: 0)

cTop

concentration of solute 1 at top (default: 0)

cBot

concentration of solute 1 at bottom (default: 0)

RootDepth

root depth (default: 0)

Value

tibble with defaults for atmospheric parameters

Examples

defaults_atmosphere()

Get Atmosphere Headers

Description

Get Atmosphere Headers

Usage

get_atmosphere_headers()

Value

vector with atmosphere headers for "ATMOSPH.in"

Examples

get_atmosphere_headers()

Helper Function: Get Metadata of Outputs ('A_LEVEL.out', 'T_LEVEL.out')

Description

Helper Function: Get Metadata of Outputs ('A_LEVEL.out', 'T_LEVEL.out')

Usage

get_output_meta(output)

Arguments

output

imported output as retrieved by read_alevel or read_tlevel

Value

returns metainformation list with sublists "general" and "units" of imported 'A_LEVEL.out' or 'T_LEVEL.out' file

Examples

test_file <- function(x) system.file("extdata/model/test", x, package = "kwb.hydrus1d")
alevel <- read_alevel(path = test_file("A_LEVEL.out"))
get_output_meta(alevel)
tlevel <- read_tlevel(path = test_file("T_LEVEL.out"))
get_output_meta(tlevel)

Helper function: get units list from meta general

Description

Helper function: get units list from meta general

Usage

get_units_list(meta_general)

Arguments

meta_general

as retrieved by read_meta_general

Value

list with elements unit_L, unit_T and unit_M

Examples

path_tlevel <- system.file("extdata/model/test/T_LEVEL.out", package = "kwb.hydrus1d")
content <- readLines(path_tlevel)
content_general <- content[3:5]
cat(content_general)
meta_general <- read_meta_general(content_general)
get_units_list(meta_general)

Prepare Atmosphere Input

Description

Prepare Atmosphere Input

Usage

prepare_atmosphere_input(inputs, defaults = defaults_atmosphere())

Arguments

inputs

tibble or data.frame with user defined inputs for parameters defined in get_atmosphere_headers

defaults

defaults for undefined parameters. Default: defaults_atmosphere

Value

tibble with atmosphere values

Examples

inputs <- tibble::tibble(tAtm = 1:10, Prec = 10, rSoil = 0.4)
prepare_atmosphere_input(inputs)

Read A_LEVEL.out

Description

A-level information is printed each time a time-dependent boundary condition is specified. The information is directed to output file A_LEVEL.OUT.

Usage

read_alevel(path, dbg = FALSE)

Arguments

path

full path to A_LEVEL.out file

dbg

show debug messages (default: FALSE)

Value

imports A_LEVEL out with tidy column names and saves metainformation in attributes 'meta_general' and 'meta_units'

time

Time, t, at current time-level [T]

sum_r_top

Cumulative potential surface flux [L] (infiltration/evaporation: -/+)

sum_r_root

Cumulative potential transpiration [L]

sum_v_top

Cumulative value of the actual surface flux [L] (infiltration/evaporation: -/+) [-]

sum_v_root

Cumulative value of the actual transpiration [L]

sum_v_bot

Cumulative value of the bottom boundary flux [L] (inflow/outflow: +/-)

h_top

Pressure head at the soil surface [L]

h_root

Mean value of the pressure head in the soil root zone for which Beta(n)>0 [L]

h_bot

Pressure head at the bottom of the soil profile [L]

a_level

A-level number (current variable boundary condition number) [-]

References

https://www.pc-progress.com/Downloads/Pgm_Hydrus1D/HYDRUS1D-4.17.pdf#page=277

Examples

path_alevel <- system.file("extdata/model/test/A_LEVEL.out", package = "kwb.hydrus1d")
alevel <- read_alevel(path = path_alevel)
alevel

Helper Function: Read Meta General

Description

Helper Function: Read Meta General

Usage

read_meta_general(content_general)

Arguments

content_general

lines with content general (see example)

Value

tibble with columns description, modelstart_datetime and unit L,T,M

Examples

path_tlevel <- system.file("extdata/model/test/T_LEVEL.out", package = "kwb.hydrus1d")
content <- readLines(path_tlevel)
content_general <- content[3:5]
cat(content_general)
read_meta_general(content_general)

Read Run_Inf.out

Description

Contains time and iteration information

Usage

read_runinf(path, dbg = FALSE)

Arguments

path

full path to Run_Inf.out file

dbg

show debug messages (default: FALSE)

Value

imports Run_Inf.out with tidy column names and saves metainformation in attributes 'meta_general' and 'meta_units'

tlevel

Time-level (current time-step number) [-]

time

Time, t, at current time-level [T]

dt

Time step, delta t [T]

itr_w

Number of iterations necessary for solution of the water flow equation [-]

itr_c

Number of iterations necessary for solution of the solute transport equation [-]

it_cum

Cumulative number of iterations [-]

kod_t

Code for the boundary condition at the soil surface

kod_b

Code for the boundary condition at the bottom of the soil profile

converg

Information whether or not the numerical convergence was achieved at the current time-level

peclet

Maximum local Peclet number [-]

courant

Maximum local Courant number [-]

References

https://www.pc-progress.com/Downloads/Pgm_Hydrus1D/HYDRUS1D-4.17.pdf#page=272

Examples

path_runinf <- system.file("extdata/model/test/Run_Inf.out", package = "kwb.hydrus1d")
runinf <- read_runinf(path = path_runinf)
runinf

Read solute1.out

Description

Reads Solute output

Usage

read_solute(
  path = system.file("extdata/model/test/solute1.out", package = "kwb.hydrus1d"),
  dbg = FALSE
)

Arguments

path

full path to solute_id.out file (default: system.file("extdata/model/test/solute1.out", package = "kwb.hydrus1d"))

dbg

show debug messages (default: FALSE)

Value

imports solute_id.out with tidy column names and saves metainformation in attributes 'meta_general' and 'meta_units'

time

Time, t, at current time-level [T]

cv_top

Actual solute flux across the soil surface [ML-2 T -1] (inflow/outflow: +/-)

cv_bot

Actual solute flux across the bottom of the soil profile [ML-2 T -1] (inflow/outflow: +/-)

sum_cv_top

Cumulative solute flux across the soil surface [ML-2] (inflow/outflow: +/-)

sum_cv_bot

Cumulative solute flux across the bottom of the soil profile [ML-2] (inflow/outflow: +/-)

sum_cv_ch0

Cumulative amount of solute added to the flow region by zero-order reactions [ML-2] (negative when removed from the system)

sum_cv_ch1

Cumulative amount of solute removed from the flow region by first-order reactions [ML-2] (negative removed from the system).

c_top

Solute concentration at the soil surface [ML-3]

c_root

Mean solute concentration of the root zone [ML-3]

c_bot

Solute concentration at the bottom of the soil profile [ML-3]

cv_root

Actual root solute uptake in the root zone [ML-2 T -1] (positive when removed from the system)

sum_cv_root

Cumulative amount of solute removed from the flow region by root water uptake S [ML-2] (positive when removed from the system)

sum_cv_n_eql

Cumulative mass transfer to either kinetic adsorption sites (type-2 adsorption sites), or to the immobile liquid region [ML-2] (inflow/outflow: +/-).

t_level

Time-level (current time-step number) [-]

c_gwl

Average concentration in the saturated zone [ML-3] (in the groundwater)

c_run_off

Solute flux in the runoff ([ML-3] * [LT-1]) [ML-2T-1]

sum_c_run_off

Cumulative solute flux in the runoff ([ML-3] * [LT-1]* [T]) [ML-2]

cv_i

Solute flux at the first through third observation node ([ML-3] * [LT-1]) [ML-2T-1]

sum_cv_i

cumulative solute flux at the first through third observation node ([ML-3] * [LT-1] * [T]) [ML-2]. Total solute fluxes are reported when only one solute is simulated. Only convective fluxes (for the first solute) are reported when 2 or more solutes are simulated

References

https://www.pc-progress.com/Downloads/Pgm_Hydrus1D/HYDRUS1D-4.17.pdf#page=273

Examples

path_solute <- system.file("extdata/model/test/solute1.out", package = "kwb.hydrus1d")
solute <- read_solute(path = path_solute)
solute

Read T_LEVEL.out

Description

Stores pressure heads and fluxes on the boundaries and in the root zone.

Usage

read_tlevel(path, dbg = FALSE)

Arguments

path

full path to T_LEVEL.out file

dbg

show debug messages (default: FALSE)

Value

imports T_LEVEL out with tidy column names and saves metainformation in attributes 'meta_general' and 'meta_units'

time

Time, t, at current time-level [T]

r_top

Potential surface flux [LT-1] (infiltration/evaporation: -/+)

r_root

Potential transpiration rate [LT-1]

v_top

Actual surface flux [LT-1] (infiltration/evaporation: -/+)

v_root

Actual transpiration rate [LT-1]

v_bot

Actual flux across the bottom of the soil profile [LT-1] (inflow/outflow +/-)

sum_r_top

Cumulative value of the potential surface flux [L] (infiltration/evaporation: -/+)

sum_r_root

Cumulative value of the potential transpiration rate [L]

sum_v_top

Cumulative value of the actual surface flux [L]

sum_v_root

Cumulative value of the actual transpiration rate [L] (infiltration/evaporation: -/+)

sum_v_bot

Cumulative value of the actual flux across the bottom of the soil profile [LT-1] (inflow/outflow +/-)

h_top

Pressure head at the soil surface [L]

h_root

Mean value of the pressure head over the region for which Beta(n) > 0 (i.e. within the root zone) [L]

h_bot

Pressure head at the bottom of the soil profile [L]

run_off

Surface runoff [LT-1]

sum_run_off

Cumulative surface runoff [L]

volume

Volume of water in the entire flow domain [L]

sum_infil

Cumulative infiltration [L]

sum_evap

Cumulative actual evaporation [L]

t_level

Time-level (current time-step number) [-]

cum_w_trans

Cumulative mass transfer between the mobile and immobile regions for dual porosity model [L]

snow_layer

Thickness of snow layer, expressed as the "snow water equivalent" (the amount of water contained within the snowpack) [L]

References

https://www.pc-progress.com/Downloads/Pgm_Hydrus1D/HYDRUS1D-4.17.pdf#page=271

Examples

path_tlevel <- system.file("extdata/model/test/T_LEVEL.out", package = "kwb.hydrus1d")
tlevel <- read_tlevel(path = path_tlevel)
tlevel

Run Model

Description

Run Model

Usage

run_model(
  exe_path = check_hydrus_exe(),
  model_path = system.file("extdata/model/test", package = "kwb.hydrus1d"),
  ...
)

Arguments

exe_path

path to Hydrus1D executable v4.17.040 (default: as retrieved by check_hydrus_exe)

model_path

path to model directory (default: system.file("extdata/model/test", package = "kwb.hydrus1d"))

...

additional arguments passed to shell

Value

runs HYDRUS 1D model

Examples

run_model()

Write "ATMOSPH.IN" input file

Description

Write "ATMOSPH.IN" input file

Usage

write_atmosphere(
  atm,
  MaxAL = 365,
  DailyVar = FALSE,
  SinusVar = FALSE,
  lLai = FALSE,
  lBCCycles = FALSE,
  lInterc = FALSE,
  hCritS = 0,
  round_digits = 2,
  remove_scientific = TRUE
)

Arguments

atm

tibble of input data as defined in prepare_atmospherice_input

MaxAL

Number of meteorological records

DailyVar

TRUE if HYDRUS-1D is to generate daily variations in evaporation and transpiration (see section 2.7.2.)., otherwise: FALSE (default: FALSE)

SinusVar

TRUE if HYDRUS-1D is to generate sinusoidal variations in precipitation (see section 2.7.2.), otherwise: FALSE(default: FALSE)

lLai

Logical variable indicating that potential evapotranspiration is to be divided into potential evaporation and potential transpiration using eq. (2.75). (default: FALSE)

lBCCycles

TRUE if a set of boundary conditions is to be repeated multiple times, otherwise FALSE(default: FALSE)

lInterc

TRUE if interception is considered using eq. (2.78), otherwise FALSE (default: FALSE)

hCritS

Maximum allowed pressure head at the soil surface (L). (default: 0)

round_digits

digits used for rounding values (default: 2) of all columns besides "tAtm"

remove_scientific

if TRUE scientific notation of numbers is removed, otherwise not (default: TRUE)

Value

Creates ATMOSPH.IN input textfile

Examples

inputs <- tibble::tibble(tAtm = 1:10, Prec = 10, rSoil = 0.4)
atm <- prepare_atmosphere_input(inputs)
atm
atm_string <- write_atmosphere(atm = atm, MaxAL = nrow(atm))
cat(atm_string)