Skip to content

Commit b0b1c7b

Browse files
committed
Update to use unitClip
1 parent 761c4ad commit b0b1c7b

5 files changed

Lines changed: 10 additions & 17 deletions

File tree

src/sipnet/depeffects.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
#include "state.h"
99

1010
double getClippedWaterFrac(double water, double whc) {
11-
return fmin(fmax(water / whc, 0.0), 1.0);
11+
return unitClip(water / whc);
1212
}
1313

1414
double calcAnaerobicIndex(double water, double whc) {
1515
double f_whc = getClippedWaterFrac(water, whc);
1616
double f_a = params.fAnoxia;
1717

1818
// Anaerobic index (oxygen limitation proxy)
19-
return fmin(fmax((f_whc - f_a) / (1 - f_a), 0), 1);
19+
return unitClip((f_whc - f_a) / (1 - f_a));
2020
}
2121

2222
double calcRespMoistEffect(double water, double whc) {
@@ -45,7 +45,7 @@ double calcRespMoistEffect(double water, double whc) {
4545
// at intermediate moisture, reduced under saturated/anoxic conditions
4646

4747
// Aerobic water availability (dry limitation)
48-
double D_aer = fmin(fmax(f_whc / params.fAnoxia, 0), 1);
48+
double D_aer = unitClip(f_whc / params.fAnoxia);
4949
// Anaerobic index (oxygen limitation proxy)
5050
double A = calcAnaerobicIndex(water, whc);
5151
// Uni-modal moisture response

src/sipnet/limitations.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ void checkLeafOnLimitation(double *leafOnFlux) {
4141
nLimiter = availableN / leafOnNDemand;
4242
}
4343
}
44-
double limitation = fmin(cLimiter, nLimiter);
45-
limitation = fmax(fmin(limitation, 1.0), 0.0);
44+
double limitation = unitClip(fmin(cLimiter, nLimiter));
4645

4746
if (limitation < 1) {
4847
*leafOnFlux *= limitation;

src/sipnet/nitrogen.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ static void calcNPoolFluxes(void) {
5959
fluxes.coarseRootLoss / params.woodCN;
6060
// saturationFraction capped between zero and one
6161
double saturationFraction =
62-
(ctx.carbonSaturation)
63-
? (fmin(1.0, fmax(0.0, envi.soilC / params.soilCSaturation)))
64-
: 0.0;
62+
ctx.carbonSaturation ? unitClip(envi.soilC / params.soilCSaturation)
63+
: 0.0;
6564

6665
// litter
6766
// The litter org N flux is determined by the carbon fluxes from wood and leaf

src/sipnet/sipnet.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,9 +1660,8 @@ void updatePoolsForSoil(void) {
16601660
// pool below saturation level, all inputs will be directed to envi.litterC
16611661
// pool while envi.soilC is above saturation level
16621662
double saturationFraction =
1663-
(ctx.carbonSaturation)
1664-
? (fmin(1.0, fmax(0.0, envi.soilC / params.soilCSaturation)))
1665-
: 0.0;
1663+
ctx.carbonSaturation ? unitClip(envi.soilC / params.soilCSaturation)
1664+
: 0.0;
16661665
// :: from [2], litter model description
16671666
envi.litterC += (fluxes.woodLitter + fluxes.leafLitter +
16681667
(soilInputs * saturationFraction) - fluxes.litterToSoil -

tests/sipnet/test_modeling/testCarbonSaturation.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,10 @@ int checkLitter(double pool) {
6060
}
6161

6262
void calcCSaturation(double *expSoilC, double *expLitterC) {
63-
double saturationFraction;
6463
double soilInputs =
6564
fluxes.coarseRootLoss + fluxes.fineRootLoss + fluxes.litterToSoil;
66-
67-
saturationFraction =
68-
(ctx.carbonSaturation)
69-
? (fmin(1.0, fmax(0.0, *expSoilC / params.soilCSaturation)))
70-
: 0.0;
65+
double saturationFraction =
66+
ctx.carbonSaturation ? unitClip(*expSoilC / params.soilCSaturation) : 0.0;
7167

7268
*expLitterC += soilInputs * saturationFraction * climate->length;
7369

0 commit comments

Comments
 (0)