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

Development for v6.3.0 #249

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Development for v6.3.0 #249

wants to merge 15 commits into from

Conversation

N1ckP3rsl3y
Copy link
Contributor

  • Update SOILWAT2 to v8.1.0

- Update function calls where the name has changes and/or the argument(s) changed
- SOILWAT2 no longer has `files_nc.in`
- Switch the following types: RealD -> double and RealF -> float
- SW_WEATHER_HIST is no longer a pointer to a pointer, but is one array of SW_WEATHER_HIST instances

- SOILWAT2 now provides a function that handles the calculations/setting of weather data
	* Remove calculations from `rSW2_set_weather_hist()`
	* Store all weather data in a temporary location
	* Call SOILWAT2's function `SW_WTH_setWeatherValues()` to calculate/set the weather

- Update names changes of and within the struct SW_PATH_INPUTS
- Update the setting of `swrcp` to set `swrcpOM` and `swrcpMineralSoil`
- Update the use flag `inputsProvideSWRCp` over `site_has_swrcpMineralSoil`
- New helper function to `onSet_SW_SIT_tranp()`
	* Move the setting of transpiration from `onSet_SW_SIT()`
	* Set after we read soil information
Copy link
Member

@dschlaep dschlaep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we need a couple more rSOILWAT2 updates to reflect all SOILWAT2 changes related to SWRC parameters (separate inputs of organic and mineral ps from calculated bulk; and provide sapric depth as input) -- see more detailed comments. Thanks!

@@ -152,18 +153,18 @@ static void onSet_SW_LYR(SEXP SW_LYR, LOG_INFO* LogInfo) {
imperm = p_Layers[i + j * 10];
soiltemp = p_Layers[i + j * 11];

v->width[lyrno] = dmax - dmin;
v->soils.width[lyrno] = dmax - dmin;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onSet_SW_LYR() should also v->soils.depths[lyrno] = dmax; as the updated SOILWAT2's SW_LYR_read()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should onSet_SW_LYR() now also call SW_Site->n_evap_lyrs = nlayers_bsevap(SW_Site->soils.evap_coeff, SW_Site->n_layers); as the updated SOILWAT2's SW_LYR_read()?

@@ -184,7 +185,7 @@ static SEXP onGet_SW_SWRCp(void) {
int i, k;
SW_SITE *v = &SoilWatRun.Site;
SEXP SWRCp, SWRCp_names, SWRCp_names_y;
RealD *p_SWRCp;
double *p_SWRCp;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onGet_SW_SWRCp() should now

  • copy v->soils.swrcpMineralSoil[i][k] into "p_SWRCp"
  • copy v->swrcpOM into new "omSWRCp"

This is because SOILWAT2 now distinguishes between SWRCp in the mineral soil swrcpMineralSoil (user inputs), SWRCp in the organic matter swrcpOM (user input) and the calculated bulk soil SWRCp swrcp. For rSOILWAT2, SWRCp (slot "SWRCp" of S4 class "swSoils") is equivalent to SWRCp in the mineral soil (user inputs) -- but we cannot rename it for backwards compatibility .... That also means that we need now to add a new slot "omSWRCp" to S4 class "swSoils" for equivalency with SOILWAT2. And similarly, S4 class "swSite" gains a new slot "depthSapric"

src/rSW_Site.c Outdated
if (isMineral) {
v->soils.swrcpMineralSoil[i][k] = p_SWRCp[i + (v->n_layers) * k];
} else {
v->swrcpOM[i][k] = p_SWRCp[i + (v->n_layers) * k];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onSet_SW_SWRCp() -- see longer comment for onGet_SW_SWRCp()

  • copy p_SWRCp into v->soils.swrcpMineralSoil
  • copy new "omSWRCp" into v->swrcpOM

@@ -622,28 +636,38 @@ void onSet_SW_SIT(SEXP SW_SIT, LOG_INFO* LogInfo) {
strcpy(v->site_ptf_name, CHAR(STRING_ELT(swrc_flags, 1)));
v->site_ptf_type = encode_str2ptf(v->site_ptf_name);
PROTECT(has_swrcp = GET_SLOT(SW_SIT, install("has_swrcp")));
v->site_has_swrcp = LOGICAL(has_swrcp)[0];
v->inputsProvideSWRCp = LOGICAL(has_swrcp)[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onSet_SW_SIT() -- see longer comment for onGet_SW_SWRCp()

  • copy new slot "depthSapric" to v->depthSapric

@@ -458,7 +479,7 @@ SEXP onGet_SW_SIT(void) {
setAttrib(swrc_flags, R_NamesSymbol, swrc_names);

PROTECT(has_swrcp = NEW_LOGICAL(1));
LOGICAL(has_swrcp)[0] = v->site_has_swrcp;
LOGICAL(has_swrcp)[0] = v->inputsProvideSWRCp;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onGet_SW_SIT() -- see longer comment for onGet_SW_SWRCp()

  • copyv->depthSapric to new slot "depthSapric"

N1ckP3rsl3y and others added 10 commits December 20, 2024 16:39
C code
* Update column names to hold information for organic matter
* Update the transferring of fraction organic matter between R and C
* Update the setting of swrcp mineral soil to go to and from `swrcpMineralSoil` instead of `swrcp`
* New function `onGet_SW_omSWRCp()` and `onSet_SW_omSWRCp()` to transfer swrcp organic matter between R and C, used to set SW_SOILS slots

R code
* Class `swSoils` gains new slot - omSWRCp
	- Add new prototype for omSWRCp
	- Check that slot exists and is the correct size
	- Add reset/setReplace method
	- Add slot to `sw_upgrade` method
C code
* New column name "depth_sapric"
* Update `onGet/Set_SW_SIT()` to transfer `depthSapric` to/from R and C

R code
* Add new slot "depth_sapric" to swSite
* Make sure that depth_sapric is provided
* Create replace/set/generic methods for "depth_sapric"
- sw_upgrade() for "swSite": new upgrade_soilLayers() to add new column "som_frac" (and set it to default values of 0)
- new soilLayer_dataColumns()
- fix documentation
Bugfixes for "omSWRCp"
- fix onGet_SW_omSWRCp(): values were incorrectly copied; row and column names were mixed up
- fix onSet_SW_SWRCp(): values were incorrectly copied; remove unused variable "isMineral" that prevented "site_has_swrcpMineralSoil" from being set correctly
- fix export `swSoils_omSWRCp<-()`
- fix names given to "swSoils" slot "omSWRCp": row and column names were mixed up
- fix documentation

New objects
- sw2_list_omSWRCp: list of a matrix for each implemented SWRC with parameters for fibric and sapric peat

New behavior
- example code, vignette, and unit tests now set swSoils_omSWRCp() according to the selected SWRC
- fix validity check for "swSoils"
- add missing variable "debug" for debug mode
- rSW_CTL_obtain_inputs() now calls onSet_SW_SOILS() before onSet_SW_SIT_transp() -- this change was needed because onSet_SW_SIT_transp() requires soil depth information that is only available after it was obtained by onSet_SW_SOILS()

- see SOILWAT2 commit "Input specification of transpiration regions changed from layers to soil depth" (DrylandEcology/SOILWAT2@8c6432f)
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.

2 participants