-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature swrc #322
Merged
Merged
Feature swrc #322
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
dschlaep
commented
Jul 29, 2022
- close Implement multiple soil water retention curves #315
- previously, SOILWAT2 used * Campbell 1974 as soil water retention curve SWRC (to convert between SWC and SWP) * Cosby et al. 1984 as pedotransfer function PDF (to estimate Campbell's SWRC parameters) --> this commit encapsulates SWRCs and PDFs in generalized functions so that (in the future) additional SWRCs and PDFs could be implemented and selected at run-time - struct `SW_LAYER_INFO`: * the array "swrcp[]" (replacing "thetaMatric", "psisMatric", "bMatric", and "binverseMatric") to hold parameters of any type of SWRC * "swrc_type" indicates which SWRC is selected (per soil layer) * "pdf_type" indicates which PDF would be used to estimated parameters at runtime if "swrcp_from_pdf" is TRUE - generalized PDF function `SWRC_PDF_estimate_parameters()`, replacing `water_eqn`(), and Cosby-specific version `SWRC_PDF_Cosby1984_for_Campbell1974()` - generalized function to check parameters `SWRC_check_parameters()` and Cosby-specific version `SWRC_check_parameters_for_Campbell1974()` - generalized SWC->SWP conversion function `SW_SWRC_SWCtoSWP()` and `SWRC_SWCtoSWP()`, replacing `SW_SWCbulk2SWPmatric()`, and Campbell-specific version `SWRC_SWCtoSWP_Campbell1974()` - generalized SWP->SWC conversion function `SW_SWRC_SWPtoSWC()` and `SWRC_SWPtoSWC()`, replacing `SW_SWPmatric2VWCBulk()`, and Campbell-specific version `SWRC_SWPtoSWC_Campbell1974()` - the new functions are written such that rSOILWAT2 will be able to utilize them in R code - updated documentation and unit tests - this commit reproduced output from v6.2.1: `make bin bint_run` and `diff testing/Output/ testing/Output_ref/ -qs`
* master: Fix documentation reference for `weth_found` More careful writing to `errstrs` (-Wformat-overflow=]) Collapse `ERRSTRLEN` and `MAX_ERROR` Updated approach for global variables Define variable "prepare_IterationSummary" only once
- this commit produces identical "testing/" output as v6.3.0
- they cropped in erroneously from recent merge from master branch - avoid compiler warning: `variable 'theta_1500' set but not used [-Wunused-but-set-variable]`
- The function that was reading reading soil properties from the file "soils.in" on disk is renamed from `_read_layers()` to `SW_LYR_read()`. - The function is no longer static so that it can now be called from `SW_CTL_read_inputs_from_disk()` instead of being called by `SW_SIT_read()`.
- previously, checks that we had positive moisture etc. were contained in the Campbell1974-specific functions - however, these checks will need to pass for any SWRC
- fix commit b387a87 ("Upgrade function that reads soil properties from disk")
- move code chunk from `SW_SIT_init_run()` to own dedicated function - no change in behavior
- use units of [cm/cm] instead of [100 * cm/cm] for theta - switch order of psi_sat (now swrcp[0]) and theta_sat (now swrcp[1]) - clean up function documentation - add more detailed code documentation
- new arrays `swrc2str` and `pdf2str` translate (now) internal integer codes to character string representation - new `encode_str2swrc()` and `encode_str2pdf()` translate names to internal integer codes - struct `SW_SITE` gained "site-level" values for selected SWRC/PDF names (and their internal integer codes) - element `swrcp_from_pdf` is no longer needed (pdf_type > 0 does the same) - thus, interpretation of requested PDF value is now "independent" of "SWRC" --> `SWRC_PDF_estimate_parameters()` no longer requires argument "swrc_type"
- print selected SWRC/PDF and SWRC parameter values
- `siteparam.in` gains two new inputs: "swrc_name" and "pdf_name" - if "pdf_name" is "NoPDF", then a new file `swrc_params.in` must be provided with parameter values instead -> new `SW_SWRC_read()` to read the new file `swrc_params.in` -> `files.in` is updated to hold path of new file `swrc_params.in` -> `SW_SIT_read()` is updated to read in "swrc_name" and "pdf_name" (they are stored into "site_*" and translated to internal codes), and later (by `SW_SIT_init_run()`) copied to soil layers
- fix commit 80a154e --> that commit replaced the index variable `s` with `lyr->id` to print soil layer information for messages in `SW_SIT_init_run()` but "lyr" is not available outside of soil-layer loops --> use `SW_Site.lyr[s]->id` instead where `lyr` is not defined
- strings created by `Str_Dup()` must be freed which commit 1fd9564 did not do -> replace `Str_Dup()` with `(char *) "..."` which does not need to be freed
- implemented with names "vanGenuchten1980" and "Rosetta3" - updated values: `N_SWRCs`, `N_PDFs`, `swrc2str[]`, `pdf2str[]` - updated functions: `check_SWRC_vs_PDF()`, `SWRC_check_parameters()`, `SWRC_SWCtoSWP()`, `SWRC_SWPtoSWC()` - new functions: `SWRC_check_parameters_for_vanGenuchten1980()`, `SWRC_SWCtoSWP_vanGenuchten1980`, `SWRC_SWPtoSWC_vanGenuchten1980() - updated input files: `swrc_param.in` (to explain meaning and units of parameters if "vanGenuchten1980" is selected)
…nted in C - `pdf2str[]` lists all available PDFs (whether implemented in C or rSOILWAT2) - `check_SWRC_vs_PDF()` now uses "isSW2" to determine if a PDF is available in C, in rSOILWAT2, or is not a match for the SWRC
- previously, the function returned for complete absence of soil moisture a matric tension = 0 bar (suggesting wettest conditions) -> the correct value would be something like infinity --> now, the code throws an error if there is no soil moisture * this has no consequences for normal SOILWAT2 runs, but a few unit tests needed to be updated
- improved coverage of edge cases - new unit tests for newly implemented "vanGenuchten1980" SWRC - loop over implemented SWRCs to translate SWC <-> SWP
Implement a new SWRC "XXX" and corresponding PDF "YYY" * update number of `N_SWRCs` and `N_PDFs` * add new names to `swrc2str[]` and `pdf2str[]` * implement new functions * `SWRC_check_parameters_for_XXX()` to validate parameter values * `SWRC_PDF_YYY_for_XXX()` to estimate parameter values (if implemented) * `SWRC_SWCtoSWP_XXX()` to translate moisture content to potential * `SWRC_SWPtoSWC_XXX()` to translate water potential to content * update "wrapper" functions to call new XXX/YYY-specific functions * `check_SWRC_vs_PDF()` * `SWRC_PDF_estimate_parameters()` (if PDF is implemented) * `SWRC_check_parameters()` * `SWRC_SWCtoSWP()` * `SWRC_SWPtoSWC()` * update `siteparam.in` and `swrc_param.in` * update and add new unit tests that utilize new XXX/YYY functions
- new argument "errmode" of `SWRC_SWPtoSWC()`, `SWRC_SWCtoSWP()`, `double SWRC_SWCtoSWP_Campbell1974()`, and `SWRC_SWCtoSWP_vanGenuchten1980()` - SOILWAT2 internal usage of `errmode` will be `LOGFATAL` for fatal errors if the SWC-SWP conversion cannot be carried out - other applications (e.g., rSOILWAT2) may use an `errmode` of `LOGWARN` (or similar) for non-fatal errors (and the above functions will return `SW_MISSING`) - updated unit tests to cover both fatal and non-fatal situations
- previously, SOILWAT2 used the soil water retention curve by Campbell 1974 including an estimate of theta_sat (= saturated volumetric water content) by pedotransfer functions by Cosby et al. 1984 -- yet for purposes of determining saturated conditions (outside of SWRC) utilized a different estimate of theta_sat, the one estimated by pedotransfer functions by Saxton et al. 2006 - otherwise, SOILWAT2 now uses consistently theta_sat as estimated by the selected PDF (or provided as input via `swrc_params.in` depending on the selected SWRC) -> new `SWRC_PDF_swcBulk_saturated()` delivers the correct `theta_sat` (converted to bulk soil) depending on the selected `SWRC` (and in case of `pdf_name = "Cosby1984AndOthers"` reproduces previous (legacy) behavior) -> `PDF_Saxton2006()` now returns `theta_sat` (instead of `theta_sat` converted to bulk soil)
- expectations of SWRC output to be `SW_MISSING` used `EXPECT_EQ()` which tests for exact equality --> `SW_MISSING`, however, is a floating point number --> use `EXPECT_DOULBE_EQ()` instead - this improves commit 0f6ac5d
- rename to make underlying PDF explicit in name of function, similar to `PDF_Saxton2006()` - `PDF_RawlsBrakensiek1985()` now returns `theta_min` instead of `theta_min * (1 - gravel)` --> `gravel` is no longer required as argument --> make interface similar to that of `PDF_Saxton2006()` --> update unit tests --> update function documentation --> new limits for argument `porosity` which is required to be >= 10% (based on the shape of the equation) and < 100%
- previously, SOILWAT2 used the soil water retention curve by Campbell 1974 -- yet, minimum soil moisture conditions were based on user input and/or realistic minimum values and/or on an estimate of theta_min by Rawls & Brakensiek 1985 - SOILWAT2 now uses a theta_min that is consistent with the selected SWRC, i.e., estimated by the selected PDF (or provided as input via `swrc_params.in` depending on the selected SWRC) -> new `SWRC_PDF_swcBulk_minimum()` delivers the correct `theta_min` (converted to bulk soil) depending on the selected `SWRC` (and in case of `pdf_name = "Cosby1984AndOthers"` reproduces previous (legacy) behavior) -> new `legacy_theta_min()` reproduces previous behavior (code taken from `SW_SIT_init_run()`) -> new `lower_limit_of_theta_min()` returns a "realistic" lower estimate of `theta_min` based on selected SWRC at a fixed tension
- previous commit set theta_min to 0 if Campbell1974/Cosby1984; this, however, leads to phi -> Infinity (and code breaks before that) -> we need `theta_min` > 0 so that floating point arithmetic does not break and for phi staying in a realistic range options: - fixed realistic value based on a phi_min by `lower_limit_of_theta_min()` - fixed (unrealistic) value based on floating point delta `powe(D_DELTA, 1. / swrcp[2]) * swrcp[1]` - use previous behavior, i.e., `legacy_theta_min()` --> `legacy_theta_min()` seems to be the best alternative: (i) realistic range of values, (ii) possibly sensitive to soil properties, and (iii) allows user input (e.g., for experiments)
- previously, the code was dividing by zero if the selected SWRC returned SWP = 0 bar for SWC = saturated - prior to v7.0.0, this never occurred -> now, code catches SWP = 0 bar and treats it as if at field capacity for division (here, calculating weights) -> this fixes unit tests introduced with commit f06dae5 "New water balance unit tests using vanGenuchten1980 SWRC"
- `SWRC_PDF_swcBulk_minimum()` returns now with a value even for "Campbell1974" and "NoPDF" (previously, an error was produced)
…e for simulations Floating-point arithmetic cannot calculate well with infinite values; however, SWRCs (at least Campbell's 1974 and van Genuchten's 1980 SWRCs) go to infinite tension at `theta_min`. Also, SOILWAT2's implementation of unsaturated percolation is currently not tightly linked to SWRC-specific hydraulic conductivity, i.e., soil moisture can be reduced to exactly `theta_min` which then would lead to a crash. Thus, we use a realistic lower limit of soil moisture which is determined by `SW_swcBulk_minimum()` -- instead of the SWRC-theoretical one
- the new name reflects that this is primarily focused on the value used for SOILWAT2 simulations - even though this value is in most cased copied from parameters of the selected SWRC, legacy mode for "Cosby1984AndOthers" used an alternative estimate
- `SWRC_PDF_estimate_parameters()` gains parameter `bdensity`
- updated `SWRC_PDF_Cosby1984_for_Campbell1974()` now also estimates `K_sat` - updated `SWRC_check_parameters_for_Campbell1974()` now also checks `K_sat` - updated `SWRC_check_parameters_for_vanGenuchten1980()` now also checks `K_sat`
- N_SWRCs and N_PDFs increased each by one - `swrc2str[]` and `pdf2str[]` updated with "FXW" and "neuroFX2021" (PDF will be implemented in rSOILWAT2) - new `SWRC_check_parameters_for_FXW()` to validate parameter values of FXW - new `SWRC_SWCtoSWP_FXW()` to translate moisture content to water potential * There is no inverse of FWX --> implemented bracketing algorithm "interpolate, truncate, project" (ITP) to estimate phi from theta with new `itp_FXW_for_phi()` - new `SWRC_SWPtoSWC_FXW()` to translate water potential to moisture content * new bare-bones version `FXW_phi_to_theta()` - updated "wrapper" functions to incorporate FXW: `check_SWRC_vs_PDF()`, `SWRC_check_parameters()`, `SW_swcBulk_minimum()`, `SW_swcBulk_saturated()`, `SWRC_SWCtoSWP()` where theta = 0 is no allowed, `SWRC_SWPtoSWC()` - `swE` macro defining Euler's constant - used by FXW - `FXW_h0` and `FXW_hr` macros defining FXW constants - expanded unit tests to incorporate FXW
Codecov Report
@@ Coverage Diff @@
## release/devel_v7.0.0 #322 +/- ##
========================================================
+ Coverage 59.58% 61.13% +1.54%
========================================================
Files 21 21
Lines 4429 4742 +313
========================================================
+ Hits 2639 2899 +260
- Misses 1790 1843 +53
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
- concern: the same variable `pdf_name` attempted to encode both (i) the name of the pedotransfer function and (ii) the information whether `SWRCp` values should be estimated during run-time or not * previously, the value "NoPDF" informed SOILWAT2 that `SWRCp` was not to be estimated during run-time * issue: once `pdf_name` was set to "NoPDF", SOILWAT2 and downstream applications lost all information about the utilized pedotransfer function, e.g., ** SOILWAT2 couldn't properly determine saturated water content for Campbell1974/Cosby1984AndOthers ** downstream applications couldn't use the selected pedotransfer function for additional estimation of `SWRCp` -> separate the two types of information: keep `pdf_name` (eliminate "NoPDF") and add new `has_swrcp` - `site_has_swrcp` is a new user input from "siteparam.in" * 0: Estimate with specified pedotransfer function * 1: Use values from "swrc_params.in" -> this approach allows to pass values for `pdf_name` that are not implemented as long as `SWRCp` are provided (and `site_has_swrcp` set to TRUE) -> this approach eliminate the need that SOILWAT2 includes the pedotransfer functions implemented by rSOILWAT2; this simplifies several elements and functions including: * `pdf2str` * `SWRC_PDF_estimate_parameters()` * `check_SWRC_vs_PDF()` -> increase readability of switch-statements that select SWRC or PDF: new macros that encode indices for each implemented SWRC and PDF -> update unit tests * simplified `pdf_name` start now at index 0 * only check those PDFs implemented in SOILWAT2 * utilize new `site_has_swrcp`
# Conflicts: # doc/SOILWAT2.bib
This includes completed development on - feature_veg_estimation (including feature_read_weather and feature_climate_estimation) - feature_soildensity_type # Conflicts: # SW_Site.c # doc/SOILWAT2.bib # test/test_WaterBalance.cc # testing/Input/siteparam.in
- use correct citation from "wang2022wrr" to "wang2022WRRa" - fix links to group "swrc_pdf" - fix documentation of `swc_min` in input file "siteparam.in" to prevent "preprocessing issue while doing constant expression evaluation: syntax error" with doxygen v1.9.3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.