Skip to content

Commit 6bb9785

Browse files
authored
Merge branch 'master' into ORG81-Add-formatting-auto-checks
2 parents e1338fe + 53ee178 commit 6bb9785

21 files changed

+213
-54
lines changed

.gitignore

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# build artifacts and executables
2+
# /sipnet instead of just sipnet to NOT ignore test dirs
23
*.o
34
estimate
4-
sipnet
5+
/sipnet
56
subsetData
67
transpose
78
.doxygen.stamp
@@ -10,10 +11,6 @@ transpose
1011
docs/html
1112
docs/latex
1213

13-
.DS_Store
14-
.Rproj.user
15-
.Rhistory
16-
1714
# System-specific files
1815
.DS_Store
1916
.Rproj.user

Makefile

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ DOXYFILE = docs/Doxyfile
2626
DOXYGEN_HTML_DIR = docs/html
2727
DOXYGEN_LATEX_DIR = docs/latex
2828

29-
all: estimate sipnet transpose subsetData document
29+
all: estimate sipnet transpose subsetData
3030

3131
# Only update docs if source files or Doxyfile have changed
3232
document: .doxygen.stamp
@@ -64,21 +64,12 @@ SIPNET_LIB=libsipnet.a
6464
$(SIPNET_LIB): $(SIPNET_LIB)($(SIPNET_OFILES))
6565
ranlib $(SIPNET_LIB)
6666

67-
test: pretest $(SIPNET_TEST_DIRS) posttest $(SIPNET_LIB)
68-
69-
pretest:
70-
cp modelStructures.h modelStructures.orig.h
67+
test: $(SIPNET_TEST_DIRS) $(SIPNET_LIB)
7168

7269
# The dash in the build command tells make to continue if there are errors, allowing cleanup
73-
$(SIPNET_TEST_DIRS): pretest $(SIPNET_LIB)
74-
cp $@/modelStructures.h modelStructures.h
70+
$(SIPNET_TEST_DIRS): $(SIPNET_LIB)
7571
-$(MAKE) -C $@
7672

77-
# This is far from infallible, as model_structures.h will be in a bad place if a test
78-
# build step fails in a non-catchable way
79-
posttest: $(SIPNET_TEST_DIRS)
80-
mv modelStructures.orig.h modelStructures.h
81-
8273
testrun: $(SIPNET_TEST_DIRS_RUN)
8374

8475
$(SIPNET_TEST_DIRS_RUN):
@@ -91,7 +82,7 @@ $(SIPNET_TEST_DIRS_CLEAN):
9182
$(MAKE) -C $(basename $@) clean
9283

9384
.PHONY: all clean document estimate sipnet transpose subsetData doxygen \
94-
test $(SIPNET_TEST_DIRS) pretest posttest $(SIPNET_LIB) testrun \
85+
test $(SIPNET_TEST_DIRS) $(SIPNET_LIB) testrun \
9586
$(SIPNET_TEST_DIRS_RUN) testclean $(SIPNET_TEST_DIRS_CLEAN) help
9687

9788
help:

events.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* - "till": Parameters = [SOM decomposition modifier, litter decomposition modifier]
2121
* - "plant": Parameters = [emergence lag (days), C (g/m²), N (g/m²)]]
2222
* - "harv": Parameters = [fraction aboveground removed, fraction belowground removed, ...]
23-
* See test examples in `tests/sipnet/test_events/`.
23+
* See test examples in `tests/sipnet/test_events_infrastructure/`.
2424
*/
2525
//
2626

@@ -57,11 +57,11 @@ EventNode* createEventNode(
5757
case IRRIGATION:
5858
{
5959
double amountAdded;
60-
int location;
60+
int method;
6161
IrrigationParams *params = (IrrigationParams*)malloc(sizeof(IrrigationParams));
62-
sscanf(eventParamsStr, "%lf %d", &amountAdded, &location);
62+
sscanf(eventParamsStr, "%lf %d", &amountAdded, &method);
6363
params->amountAdded = amountAdded;
64-
params->location = location;
64+
params->method = method;
6565
event->eventParams = params;
6666
}
6767
break;
@@ -114,7 +114,7 @@ EventNode* createEventNode(
114114
return event;
115115
}
116116

117-
enum EventType getEventType(char *eventTypeStr) {
117+
event_type_t getEventType(char *eventTypeStr) {
118118
if (strcmp(eventTypeStr, "irrig") == 0) {
119119
return IRRIGATION;
120120
} else if (strcmp(eventTypeStr, "fert") == 0) {

events.h

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,63 @@
1-
//
2-
// Created by Michael J Longfritz on 11/8/24.
3-
//
4-
51
#ifndef EVENTS_H
62
#define EVENTS_H
73

8-
#include "modelStructures.h"
9-
10-
enum EventType {
4+
typedef enum EventType
5+
{
116
FERTILIZATION,
127
HARVEST,
138
IRRIGATION,
149
PLANTING,
1510
TILLAGE,
1611
UNKNOWN_EVENT
17-
};
12+
} event_type_t;
1813

19-
typedef struct HarvestParams {
14+
typedef enum IrrigationMethod
15+
{
16+
CANOPY = 0,
17+
SOIL = 1,
18+
FLOOD = 2 // placeholder, not supported yet
19+
} irrigation_method_t;
20+
21+
typedef struct HarvestParams
22+
{
2023
double fractionRemovedAbove;
2124
double fractionRemovedBelow;
2225
double fractionTransferredAbove; // to surface litter pool
2326
double fractionTransferredBelow; // to soil litter pool
2427
} HarvestParams;
2528

26-
typedef struct IrrigationParams {
29+
typedef struct IrrigationParams
30+
{
2731
double amountAdded;
28-
int location; // 0=canopy, 1=soil
32+
irrigation_method_t method;
2933
} IrrigationParams;
3034

31-
typedef struct FertilizationParams {
35+
typedef struct FertilizationParams
36+
{
3237
double orgN;
3338
double orgC;
3439
double minN;
35-
//double nh4_no3_frac; for two-pool version
40+
// double nh4_no3_frac; for two-pool version
3641
} FertilizationParams;
3742

38-
typedef struct PlantingParams {
43+
typedef struct PlantingParams
44+
{
3945
int emergenceLag;
4046
double addedC;
4147
double addedN;
4248
} PlantingParams;
4349

44-
typedef struct TillageParams {
50+
typedef struct TillageParams
51+
{
4552
double fractionLitterTransferred;
4653
double somDecompModifier;
4754
double litterDecompModifier;
4855
} TillageParams;
4956

5057
typedef struct EventNode EventNode;
51-
struct EventNode {
52-
enum EventType type;
58+
struct EventNode
59+
{
60+
event_type_t type;
5361
int loc, year, day;
5462
void *eventParams;
5563
EventNode *nextEvent;
@@ -62,7 +70,6 @@ struct EventNode {
6270
* if there are no events). It is assumed that the events are ordered first by location
6371
* and then by year and day.
6472
*/
65-
EventNode** readEventData(char *eventFile, int numLocs);
66-
73+
EventNode **readEventData(char *eventFile, int numLocs);
6774

68-
#endif //EVENTS_H
75+
#endif // EVENTS_H

exitCodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ typedef enum {
1515
EXIT_CODE_SUCCESS = 0,
1616
EXIT_CODE_FAILURE = 1, // generic failure
1717
// code 2 typically has a special meaning, see above
18-
EXIT_CODE_UNKNOWN_EVENT = 3
18+
EXIT_CODE_UNKNOWN_EVENT_TYPE_OR_PARAM = 3
1919
} exit_code_t;
2020

2121
#endif

sipnet.c

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@
7878
// do we have a separate litter water layer, used for evaporation?
7979
// if complex water is off, then litter water is off: litter water layer wouldn't do anything
8080

81+
#if LITTER_WATER & EVENT_HANDLER
82+
#error EVENT_HANDLER and LITTER_WATER may not both be activated
83+
#endif
84+
// We do not handle having both LITTER_WATER and EVENT_HANDLING on; this may
85+
// be implemented in a later phase
86+
8187
#define LITTER_WATER_DRAINAGE 1 && (LITTER_WATER)
8288
// does water from the top layer drain down into bottom layer even if top layer not overflowing?
8389
// if litter water is off, then litter water drainage is off: litter water drainage wouldn't do anything
@@ -2271,7 +2277,7 @@ void updateTrackers(double oldSoilWater) {
22712277
trackers.LAI = envi.plantLeafC/params.leafCSpWt;
22722278
trackers.yearlyLitter += fluxes.leafLitter;
22732279
trackers.plantWoodC = envi.plantWoodC;
2274-
//note this variable is added for Howland forest multi-model comparison includes ONLY leaf litter
2280+
//note this variable is added for Howland forest multi-model comparison includes ONLY leaf litter
22752281

22762282

22772283
// mean of soil wetness at start of time step at soil wetness at end of time step - assume linear
@@ -2298,9 +2304,28 @@ void processEvents() {
22982304
switch (locEvent->type) {
22992305
// Implementation TBD, as we enable the various event types
23002306
case IRRIGATION:
2301-
// TBD
2302-
printf("Irrigation events not yet implemented\n");
2303-
break;
2307+
{
2308+
const IrrigationParams* irrParams = locEvent->eventParams;
2309+
const double amount = irrParams->amountAdded;
2310+
if (irrParams->method == CANOPY) {
2311+
// Part of the irrigation evaporates, and the rest makes it to the soil
2312+
// Evaporated fraction
2313+
const double evapAmount = params.immedEvapFrac * amount;
2314+
fluxes.immedEvap += evapAmount;
2315+
// Remainder goes to the soil
2316+
const double soilAmount = amount - evapAmount;
2317+
envi.soilWater += soilAmount;
2318+
}
2319+
else if (irrParams->method == SOIL) {
2320+
// All goes to the soil
2321+
envi.soilWater += amount;
2322+
}
2323+
else {
2324+
printf("Unknown irrigation method type: %d\n", irrParams->method);
2325+
exit(EXIT_CODE_UNKNOWN_EVENT_TYPE_OR_PARAM);
2326+
}
2327+
}
2328+
break;
23042329
case PLANTING:
23052330
// TBD
23062331
printf("Planting events not yet implemented\n");
@@ -2319,7 +2344,7 @@ void processEvents() {
23192344
break;
23202345
default:
23212346
printf("Unknown event type (%d) in processEvents()\n", locEvent->type);
2322-
exit(EXIT_CODE_UNKNOWN_EVENT);
2347+
exit(EXIT_CODE_UNKNOWN_EVENT_TYPE_OR_PARAM);
23232348
}
23242349

23252350
locEvent = locEvent->nextEvent;
@@ -2348,13 +2373,11 @@ void updateState() {
23482373
soilDegradation(); // This updates all the soil functions
23492374

23502375
#if MODEL_WATER // water pool updating happens here:
2351-
23522376
#if LITTER_WATER // (2 soil water layers; litter water will only be on if complex water is also on)
23532377
envi.litterWater += (fluxes.rain + fluxes.snowMelt - fluxes.immedEvap - fluxes.fastFlow
23542378
- fluxes.evaporation - fluxes.topDrainage) * climate->length;
23552379
envi.soilWater += (fluxes.topDrainage - fluxes.transpiration - fluxes.bottomDrainage)
23562380
* climate->length;
2357-
23582381
#else // LITTER_WATER = 0 (only one soil water layer)
23592382
// note: some of these fluxes will always be 0 if complex water is off
23602383
envi.soilWater += (fluxes.rain + fluxes.snowMelt - fluxes.immedEvap - fluxes.fastFlow
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)