The workflow below describes all the steps required for:
Running it from within
R
by using the command line (cmd
) andImporting and Analysing the
HYDRUS1D
results within R.
Install R Package
# Enable this universe
options(repos = c(
kwbr = 'https://kwb-r.r-universe.dev',
CRAN = 'https://cloud.r-project.org'))
# Install R package
install.packages('kwb.hydrus1d')
Define Paths
paths_list <- list(
exe_dir = system.file("extdata/model", package = "kwb.hydrus1d"),
model_name = "test",
model_dir = "<exe_dir>/<model_name>",
atmosphere = "<model_dir>/ATMOSPH.IN",
a_level = "<model_dir>/A_LEVEL.out",
t_level = "<model_dir>/T_LEVEL.out",
runinf = "<model_dir>/Run_Inf.out",
solute_id = 1L,
solute = "<model_dir>/solute<solute_id>.out"
)
paths <- kwb.utils::resolve(paths_list)
Run Model
exe_path <- kwb.hydrus1d::check_hydrus_exe(dir = paths$exe_dir,
skip_preinstalled = TRUE)
#> Checking if download of HYDRUS1D executable v4.17.0140 from 'https://github.com/mrustl/hydrus1d/archive/refs/tags/v4.17.0140.zip' was successful ... ok. (0.00 secs)
kwb.hydrus1d::run_model(exe_path = exe_path,
model_path = paths$model_dir)
#> Warning in shell(cmd = sprintf("cd %s && %s", fs::path_abs(target_dir), : 'cd
#> D:/a/_temp/Library/kwb.hydrus1d/extdata/model && H1D_CALC.exe' execution failed
#> with error code 24
Read Results
a_level <- kwb.hydrus1d::read_alevel(paths$a_level)
a_level
#> # A tibble: 1,279 × 10
#> time sum_r_top sum_r_root sum_v_top sum_v_root sum_v_bot h_top h_root
#> * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 0.25 0 0.0698 0 -0.00173 -1 e5 0
#> 2 2 -0.2 0 -0.380 0 -0.00346 -8.35e1 0
#> 3 3 -0.02 0 -0.200 0 -0.00520 -2.00e3 0
#> 4 4 -0.14 0 -0.320 0 -0.00693 -1.05e2 0
#> 5 5 -0.13 0 -0.310 0 -0.00866 -1.25e2 0
#> 6 6 -0.0000000270 0 -0.209 0 -0.0104 -1 e5 0
#> 7 7 0.22 0 -0.177 0 -0.0121 -1 e5 0
#> 8 8 0.27 0 -0.161 0 -0.0139 -1 e5 0
#> 9 9 0.45 0 -0.146 0 -0.0156 -1 e5 0
#> 10 10 0.63 0 -0.135 0 -0.0173 -1 e5 0
#> # ℹ 1,269 more rows
#> # ℹ 2 more variables: h_bot <dbl>, a_level <dbl>
t_level <- kwb.hydrus1d::read_tlevel(paths$t_level)
t_level
#> # A tibble: 17,649 × 22
#> time r_top r_root v_top v_root v_bot sum_r_top sum_r_root sum_v_top
#> * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0.111 0.25 0 0.25 0 -0.00173 0.0278 0 0.0278
#> 2 0.148 0.25 0 0.25 0 -0.00173 0.0370 0 0.0370
#> 3 0.164 0.25 0 0.25 0 -0.00173 0.0410 0 0.0410
#> 4 0.171 0.25 0 0.25 0 -0.00173 0.0428 0 0.0428
#> 5 0.180 0.25 0 0.0977 0 -0.00173 0.0450 0 0.0437
#> 6 0.184 0.25 0 0.0786 0 -0.00173 0.0460 0 0.0440
#> 7 0.189 0.25 0 0.0819 0 -0.00173 0.0473 0 0.0444
#> 8 0.196 0.25 0 0.0840 0 -0.00173 0.0490 0 0.0450
#> 9 0.204 0.25 0 0.0816 0 -0.00173 0.0511 0 0.0457
#> 10 0.216 0.25 0 0.0774 0 -0.00173 0.0539 0 0.0465
#> # ℹ 17,639 more rows
#> # ℹ 13 more variables: sum_v_root <dbl>, sum_v_bot <dbl>, h_top <dbl>,
#> # h_root <dbl>, h_bot <dbl>, run_off <dbl>, sum_run_off <dbl>, volume <dbl>,
#> # sum_infil <dbl>, sum_evap <dbl>, t_level <dbl>, cum_w_trans <dbl>,
#> # snow_layer <dbl>
runinf <- kwb.hydrus1d::read_runinf(paths$runinf)
runinf
#> # A tibble: 17,649 × 11
#> t_level time dt itr_w itr_c it_cum kod_t kod_b converg peclet courant
#> * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <lgl> <dbl> <dbl>
#> 1 1 0.111 0.111 5 1 25 -4 -5 TRUE 0.1 0.18
#> 2 2 0.148 0.0370 3 1 38 -4 -5 TRUE 0.1 0.075
#> 3 3 0.164 0.0160 2 1 50 -4 -5 TRUE 0.1 0.034
#> 4 4 0.171 0.00695 2 1 62 -4 -5 TRUE 0.1 0.015
#> 5 5 0.180 0.00904 3 1 65 -4 -5 TRUE 0.1 0.009
#> 6 6 0.184 0.00392 2 1 77 4 -5 TRUE 0.1 0.003
#> 7 7 0.189 0.00509 2 1 79 4 -5 TRUE 0.1 0.004
#> 8 8 0.196 0.00662 2 1 81 4 -5 TRUE 0.1 0.006
#> 9 9 0.204 0.00861 2 1 83 4 -5 TRUE 0.1 0.007
#> 10 10 0.216 0.0112 2 1 85 4 -5 TRUE 0.1 0.009
#> # ℹ 17,639 more rows
solute <- kwb.hydrus1d::read_solute(paths$solute)
solute
#> # A tibble: 17,649 × 19
#> time cv_top cv_bot sum_cv_top sum_cv_bot cv_ch0 cv_ch1 c_top c_root c_bot
#> * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 0.111 0 0 0 0 0 0 0 0 0
#> 2 0.148 0 0 0 0 0 0 0 0 0
#> 3 0.164 0 0 0 0 0 0 0 0 0
#> 4 0.171 0 0 0 0 0 0 0 0 0
#> 5 0.180 0 0 0 0 0 0 0 0 0
#> 6 0.184 0 0 0 0 0 0 0 0 0
#> 7 0.189 0 0 0 0 0 0 0 0 0
#> 8 0.196 0 0 0 0 0 0 0 0 0
#> 9 0.204 0 0 0 0 0 0 0 0 0
#> 10 0.216 0 0 0 0 0 0 0 0 0
#> # ℹ 17,639 more rows
#> # ℹ 9 more variables: cv_root <dbl>, sum_cv_root <dbl>, sum_cv_n_eql <dbl>,
#> # t_level <dbl>, c_gwl <dbl>, c_run_off <dbl>, sum_c_run_off <dbl>,
#> # cv_i <dbl>, sum_cv_i <dbl>