Skip to content
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

Release/devel v7.1.0 #348

Merged
merged 279 commits into from
Jun 9, 2023
Merged

Release/devel v7.1.0 #348

merged 279 commits into from
Jun 9, 2023

Conversation

dschlaep
Copy link
Member

@dschlaep dschlaep commented Apr 3, 2023

dschlaep and others added 30 commits March 2, 2022 16:44
- 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)
- values estimated using rSOILWAT2 which calls "Rosetta3"
--> these tests currently fail:

```
[ RUN      ] WaterBalanceTest.WithSWRCvanGenuchten1980
WB (1980-113): aet=1.509554, pet=0.396699
WB (1980-115): aet=1.075805, pet=0.383362
WB (1981-101): aet=2.136892, pet=0.327267
...
test/test_WaterBalance.cc:216: Failure
Expected equality of these values:
  0
  SW_Soilwat.wbError[i]
    Which is: 204
Water balance error in test 0: AET <= PET
```
- `swrcp[0]` is the suction at air-entry in units of cm of water (Campbell 1974)
- improved error messages
- new unit test for saturated conditions
- testing SWP->SWC conversion to meet bounds for a large range of SWP values
- new unit tests to check that conversions are the inverse of each other over possible range of SWP values
- death tests: loop over all implemented SWRCs; clean up unnecessary tests
- document valid range for each SWRC and function
- document range over which pairs of SWRC functions are each other's inverse function
- improve logic
- now, SWP = 0 bar is returned for saturated content
- make sure that function fails if soil moisture is at 0 or minimum level

-> this commit causes tiny deviations in the output of the "testing" example (related to days with very wet conditions)
- 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
- Added `allHist` double pointer to SW_WEATHER
- Adjusted `_read_weather_hist` to store weather in year it is called with
- Created function `SW_WTH_read` that allocates allHist and calls `readAllWeather`
- Created function `readAllWeather` which:
	* Reads in all weather history at once
	* Handles the case of missing weather (moved from and deleted _todays_weth)
	* Scales data depending on month (moved from `SW_WTH_new_day`)
- Deleted `SW_WTH_new_year` as it is no longer needed
- Created function that is called by `SW_WTH_deconstruct` to deallocated allHist
- Deleted static version of weth_found and is now in `readAllWeather`
- Added most of documentation from old `SW_WTH_new_year()`
	* Describing how SOILWAT handles missing weather data
- Instead of calculating number of years multiple times, it is calculated once
- n_years is initialized to 0
- Fixed how the months days are incremented
- Fixed "temp_avg" calculations
- Removed numYears from `deallocateAllHistory` header
- Added `isnull` to prevent empty lists from attempting to free itself
- Swapped SW_Weather.scale_temp_max/min for allHist[yearIndex]->temp_max/min
dschlaep and others added 27 commits December 7, 2022 17:48
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
- close #330 (the issue raised was not a problem but on purpose)
-> clarify CO2 effects on tree biomass: CO2 effects on tree biomass restricted to percent live biomass, i.e., total tree biomass is constant while live biomass is increasing
-> simplify struct `VegType`: remove "CO2_biomass" and "CO2_pct_live" because they were used only in `SW_VPD_new_year()`
- addressing "warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]"

-> explicitly state that function takes zero arguments (i.e., void)

Note: the same warning occurs in "pcg" submodule
```
pcg/pcg_basic.c:69:22: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
   uint32_t pcg32_random()
```
- motivated by upcoming changes in R-devel (>= v4.3)

- see https://cran.r-project.org/doc/manuals/r-devel/NEWS.html: "The use of sprintf and vsprintf from C/C++ has been deprecated in macOS 13 and is a known security risk. R CMD check now reports (on all platforms) if their use is found in the compiled code: replace by snprintf or vsnprintf"
-> see corresponding commit in rSOILWAT2 72845bb020a9c4d8cbe5a513f6a472af19d7c7d1
Feature swrc

* close #315 

Multiple soil water release curves (`SWRC`) are now implemented and can be
selected with new input `swrc_name`. Implemented `SWRCs` currently include
`"Campbell1974"`, `"vanGenuchten1980"`, and `"FXW"`. New input `has_swrcp`
determines if parameters for a `SWRC` are estimated at run-time via an
implemented pedotransfer function (`PTF`) based on new input `ptf_name` or
if they are provided as inputs via new input file `"swrc_params.in"`.
`rSOILWAT2` implements additional pedotransfer functions. See documentation
entry of `"swrc_ptf"` for additional details and for guidance on how to
implement additional `SWRCs` and `PTFs` (issue #315; @dschlaep).
- addressing #89

- `git mv previous_path target_path` to "rename" folders and files without losing git history

- external: googletest and pcg submodules
- src: SOILWAT2 source code
- include: SOILWAT2 header files
- tests/example: example inputs for a SOILWAT2 run, previously "testing"
- tests/gtests: unit tests based on googletest, previously "test"

- note: additional commits to complete #89 will need to update file path names, makefile, etc.
- addressing #89

- update file paths (see previous commit 90b1741 "Re-organize repository (part 1)"

- note: additional commits to complete #89 will need to update makefile and scripts
- address #89

- update makefiles, scripts, and continuous integration setup

(see previous commit 90b1741 "Re-organize repository (part 1)"
(see previous commit dc521a4 "Re-organize repository (part 2)"
- close #335

- gcc12 issued `warning: array subscript 6 is above array bounds of 'int[6]' [-Warray-bounds]` for `if (valopts[op]) {` while referencing 'valopts'
Feature restructure

- close #89 

- new folder organization with
    - bin
    - build
        - sw2
        - test
    - include
    - external
        - googletest
        - pcg
    - src
    - tests
        - example
        - gtests
    - tools
# Conflicts:
#	NEWS.md
#	include/SW_Output.h
#	src/SW_Output.c
#	src/SW_VegEstab.c
#	testing/Input/bouteloua.estab
#	testing/Input/bromus.estab
#	testing/Input/estab/bouteloua.estab
#	testing/Input/estab/bromus.estab
#	tests/example/Input/bouteloua.estab
#	tests/example/Input/bromus.estab
#	tests/gtests/test_SW_VegEstab.cc
- I made an error resolving merge conflicts with the previous commit 8a76c82 "Merge branch 'master' (v6.7.0) into release/devel_v7.0.0"
-> `SW_OUT_read_onekey()` gained argument `sizeof_msg`
- commit 296f123 "Merge pull request #333 from DrylandEcology/feature_restructure" caused doxygen documentation to no longer find source code
(see also commit dc521a4 "Re-organize repository (part 2)" that worked on the doxyfile)

-> update doxyfile "INPUT" to include the new locations "include/" and "src/"
- change format of doxygen "sideffect" alias as recommended since update to doxygen v1.9.3 (see commit 4248d96)
- correctly specify path to output file in "A_SOILWAT2_user_guide.md"
- bibtex is required to parse "\cite" commands in the documentation and build a bibliography
- if bibtex is missing, then doxygen still creates a working documentation
* however, the documentation will be without citations and without a bibliography
* warnings are issued and the script signals an error
…tructure

Feature fix doc after restructure

- fix so that doxygen can locate source and header files (again)
- close #334
- issue #334 was expressed if "SWDEBUG" was defined and if module "SW_Output_outarray" was compiled (i.e., for STEPWAT2 and rSOILWAT2)

- use correct format identifier "%zu" for variables of type `size_t` -- instead of "%ld" (that may or may not work)
- addressing #342
* this issue is a bug for SOILWAT2 tests but not for other setups
** SOILWAT2 simulations close the log-file `logfp`: `main()` calls `check_log()` at exit
** STEPWAT2 and rSOILWAT2 have their own `logfp` mechanisms: `SW_F_read()` does not assign a (new) value (based on "files.in") to `logfp` (if compiled as STEPWAT2 or rSOILWAT2)

- new approach for SOILWAT2 tests to close log files
* immediately close the `logfp` file connection that was created by `SW_F_read()`
* set `logfp` to NULL to silence non-error messages during tests
* update `LogError()` to behave as it already does for rSOILWAT2, i.e., if silenced, write only if error (message sent stderr) and otherwise write all message to `logfp` as previously

Specific changes:
- `check_log()` is now public, moved to module SW_Main_lib, and renamed to `sw_check_log()` to avoid a potential name conflict with STEPWAT2's `check_log()`
- `sw_check_log()` is now closing a `logfp` file connection before potentially exiting SOILWAT2 with a call to `sw_error()`

- `LogError()` now handles NULL values of `logfp` even if not rSOILWAT2, i.e., don't write messages to `logfp` if NULL -- unless it is an error, then write message to stderr

- moved handling of `logfp` from `sw_maintest.cc::main()` to `Reset_SOILWAT2_after_UnitTest()`
* immediately close the `logfp` file connection that was created by `SW_F_read()`
* set `logfp` to NULL to silence non-error messages during tests

- DeathTests now expect a specific message
- new make target "test_rep3rnd"

- shuffling and repeating tests checks that unit tests are self-sufficient and don't have undesired side-effects compromising other tests

- see also `make test_reprnd` target where tests are rep[eated] r[a]nd[omly] until user interruption
Bugfix too many open files
- `LogError()` now behaves as it already does for rSOILWAT2, i.e., if silenced, write only if error (message is sent to stderr) and otherwise write all message to logfp as previously
@dschlaep dschlaep marked this pull request as draft April 3, 2023 14:18
@codecov
Copy link

codecov bot commented Apr 3, 2023

Codecov Report

Merging #348 (fcbf597) into master (0a11f71) will increase coverage by 17.29%.
The diff coverage is 76.95%.

@@             Coverage Diff             @@
##           master     #348       +/-   ##
===========================================
+ Coverage   56.16%   73.46%   +17.29%     
===========================================
  Files          20       21        +1     
  Lines        3657     4725     +1068     
===========================================
+ Hits         2054     3471     +1417     
+ Misses       1603     1254      -349     
Impacted Files Coverage Δ
src/SW_Carbon.c 69.86% <0.00%> (ø)
src/SW_Flow_lib_PET.c 98.76% <ø> (ø)
src/SW_Model.c 67.01% <0.00%> (ø)
src/SW_Output_mock.c 6.86% <ø> (ø)
src/SW_Sky.c 92.68% <0.00%> (ø)
src/Times.c 100.00% <ø> (ø)
src/mymemory.c 84.61% <ø> (ø)
src/rands.c 61.40% <ø> (ø)
src/SW_Markov.c 78.57% <7.14%> (ø)
src/SW_Main_lib.c 5.17% <7.69%> (ø)
... and 11 more

@dschlaep dschlaep merged commit 073f89e into master Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant