-
Notifications
You must be signed in to change notification settings - Fork 7
/
peatlanddecaymodule.cpp
272 lines (220 loc) · 13.2 KB
/
peatlanddecaymodule.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#include "moja/modules/cbm/peatlanddecaymodule.h"
#include "moja/modules/cbm/printpools.h"
#include <moja/flint/ivariable.h>
#include <moja/flint/ipool.h>
#include <moja/flint/ioperation.h>
#include <moja/signals.h>
#include <moja/notificationcenter.h>
#include <moja/modules/cbm/peatlandwtdbasefch4parameters.h>
namespace moja {
namespace modules {
namespace cbm {
void PeatlandDecayModule::configure(const DynamicObject& config) { }
void PeatlandDecayModule::subscribe(NotificationCenter& notificationCenter) {
notificationCenter.subscribe(signals::LocalDomainInit, &PeatlandDecayModule::onLocalDomainInit, *this);
notificationCenter.subscribe(signals::TimingInit, &PeatlandDecayModule::onTimingInit, *this);
notificationCenter.subscribe(signals::TimingStep, &PeatlandDecayModule::onTimingStep, *this);
}
void PeatlandDecayModule::doLocalDomainInit() {
_woodyFoliageDead = _landUnitData->getPool("WoodyFoliageDead");
_woodyFineDead = _landUnitData->getPool("WoodyFineDead");
_woodyCoarseDead = _landUnitData->getPool("WoodyCoarseDead");
_woodyRootsDead = _landUnitData->getPool("WoodyRootsDead");
_sedgeFoliageDead = _landUnitData->getPool("SedgeFoliageDead");
_sedgeRootsDead = _landUnitData->getPool("SedgeRootsDead");
_feathermossDead = _landUnitData->getPool("FeathermossDead");
_acrotelm_o = _landUnitData->getPool("Acrotelm_O");
_catotelm_a = _landUnitData->getPool("Catotelm_A");
_acrotelm_a = _landUnitData->getPool("Acrotelm_A");
_catotelm_o = _landUnitData->getPool("Catotelm_O");
_co2 = _landUnitData->getPool("CO2");
_ch4 = _landUnitData->getPool("CH4");
_tempCarbon = _landUnitData->getPool("TempPeatlandDecayCarbon");
_spinupMossOnly = _landUnitData->getVariable("spinup_moss_only");
baseWTDParameters = _landUnitData->getVariable("base_wtd_parameters")->value().extract<DynamicObject>();
_appliedAnnualWTD = _landUnitData->getVariable("applied_annual_wtd");
}
void PeatlandDecayModule::doTimingInit() {
_runPeatland = false;
auto& peatland_class = _landUnitData->getVariable("peatland_class")->value();
_peatlandId = peatland_class.isEmpty() ? -1 : peatland_class.convert<int>();
if (_peatlandId > 0) {
_runPeatland = true;
//get the mean anual temperture variable
const auto& defaultMAT = _landUnitData->getVariable("default_mean_annual_temperature")->value();
const auto& matVal = _landUnitData->getVariable("mean_annual_temperature")->value();
double meanAnnualTemperature = matVal.isEmpty() ? defaultMAT : matVal;
// 1) get the data by variable "peatland_decay_parameters"
const auto& peatlandDecayParams = _landUnitData->getVariable("peatland_decay_parameters")->value();
//create the PeaglandDecayParameters, set the value from the variable
decayParas = std::make_shared<PeatlandDecayParameters>();
decayParas->setValue(peatlandDecayParams.extract<DynamicObject>());
//compute the applied parameters
decayParas->updateAppliedDecayParameters(meanAnnualTemperature);
// 2) get the data by variable "peatland_turnover_parameters"
const auto& peatlandTurnoverParams = _landUnitData->getVariable("peatland_turnover_parameters")->value();
//create the PeaglandGrowthParameters, set the value from the variable
turnoverParas = std::make_shared<PeatlandTurnoverParameters>();
if (!peatlandTurnoverParams.isEmpty()) {
turnoverParas->setValue(peatlandTurnoverParams.extract<DynamicObject>());
}
// 3) get the DC (drought code), and then compute the wtd parameter
auto& peatlandWTDBaseParams = _landUnitData->getVariable("peatland_wtd_base_parameters")->value();
auto& fch4MaxParams = _landUnitData->getVariable("peatland_fch4_max_parameters")->value();
wtdFch4Paras = std::make_shared<PeatlandWTDBaseFCH4Parameters>();
wtdFch4Paras->setValue(peatlandWTDBaseParams.extract<DynamicObject>());
wtdFch4Paras->setFCH4Value(fch4MaxParams.extract<DynamicObject>());
}
}
void PeatlandDecayModule::doTimingStep() {
if (!_runPeatland) { return; }
bool spinupMossOnly = _spinupMossOnly->value();
if (spinupMossOnly) { return; }
//get current applied annual water table depth
double awtd = _appliedAnnualWTD->value();
//test degug output, time to print the pool values to check
//PrintPools::printPeatlandPools("Year ", *_landUnitData);
double deadPoolTurnoverRate = decayParas->Pt();
doDeadPoolTurnover(deadPoolTurnoverRate);
doPeatlandNewCH4ModelDecay(deadPoolTurnoverRate);
allocateCh4CO2(awtd);
//old CO2/CH4 model
//doPeatlandDecay(deadPoolTurnoverRate, awtd);
}
double PeatlandDecayModule::getCurrentYearWaterTable() {
//get the default annual drought code
auto& defaultAnnualDC = _landUnitData->getVariable("default_annual_drought_class")->value();
//get the current annual drought code
auto& annualDC = _landUnitData->getVariable("annual_drought_class")->value();
double annualDroughtCode = annualDC.isEmpty() ? defaultAnnualDC.convert<double>()
: annualDC.type() == typeid(TimeSeries) ? annualDC.extract<TimeSeries>().value()
: annualDC.convert<double>();
//compute the water table depth to be used in current step
double newCurrentYearWtd = computeWaterTableDepth(annualDroughtCode, _peatlandId);
double modifiedAnnualWtd = _appliedAnnualWTD->value();
if (modifiedAnnualWtd < 0.0) {
//there is a valid modified annual WTD for forward run only
newCurrentYearWtd = modifiedAnnualWtd;
}
return newCurrentYearWtd;
}
double PeatlandDecayModule::computeWaterTableDepth(double dc, int peatlandID) {
double retVal = 0.0;
std::string peatlandIDStr = std::to_string(peatlandID);
double wtdBaseValue = baseWTDParameters[peatlandIDStr];
retVal = -0.045 * dc + wtdBaseValue;
return retVal;
}
void PeatlandDecayModule::doDeadPoolTurnover(double deadPoolTurnoverRate) {
auto peatlandDeadPoolTurnover = _landUnitData->createProportionalOperation();
peatlandDeadPoolTurnover
->addTransfer(_woodyFoliageDead, _acrotelm_o, (turnoverParas->Pfe() * decayParas->akwfe() +
turnoverParas->Pfn() * decayParas->akwfne()) * deadPoolTurnoverRate)
->addTransfer(_woodyFineDead, _acrotelm_o, decayParas->akwsb() * deadPoolTurnoverRate)
->addTransfer(_woodyCoarseDead, _acrotelm_o, decayParas->akwc() * deadPoolTurnoverRate)
->addTransfer(_woodyRootsDead, _acrotelm_o, decayParas->akwr() * deadPoolTurnoverRate)
->addTransfer(_sedgeFoliageDead, _acrotelm_o, decayParas->aksf() * deadPoolTurnoverRate)
->addTransfer(_sedgeRootsDead, _acrotelm_o, decayParas->aksr() * deadPoolTurnoverRate)
->addTransfer(_feathermossDead, _acrotelm_o, decayParas->akfm() * deadPoolTurnoverRate)
->addTransfer(_acrotelm_o, _catotelm_a, decayParas->aka() * deadPoolTurnoverRate);
_landUnitData->submitOperation(peatlandDeadPoolTurnover);
_landUnitData->applyOperations();
}
void PeatlandDecayModule::doPeatlandNewCH4ModelDecay(double deadPoolTurnoverRate) {
auto peatlandDeadPoolDecay = _landUnitData->createProportionalOperation();
peatlandDeadPoolDecay
->addTransfer(_woodyFoliageDead, _tempCarbon, (1 - deadPoolTurnoverRate) * (turnoverParas->Pfn() * decayParas->akwfne() + turnoverParas->Pfe() * decayParas->akwfe()))
->addTransfer(_woodyFineDead, _tempCarbon, (1 - deadPoolTurnoverRate) * decayParas->akwsb())
->addTransfer(_woodyCoarseDead, _tempCarbon, (1 - deadPoolTurnoverRate) * decayParas->akwc())
->addTransfer(_woodyRootsDead, _tempCarbon, (1 - deadPoolTurnoverRate) * decayParas->akwr())
->addTransfer(_sedgeFoliageDead, _tempCarbon, (1 - deadPoolTurnoverRate) * decayParas->aksf())
->addTransfer(_sedgeRootsDead, _tempCarbon, (1 - deadPoolTurnoverRate) * decayParas->aksr())
->addTransfer(_feathermossDead, _tempCarbon, (1 - deadPoolTurnoverRate) * decayParas->akfm())
->addTransfer(_acrotelm_o, _tempCarbon, (1 - deadPoolTurnoverRate) * decayParas->aka())
->addTransfer(_catotelm_a, _tempCarbon, (1 - deadPoolTurnoverRate) * decayParas->akc())
->addTransfer(_acrotelm_a, _tempCarbon, (1 - deadPoolTurnoverRate) * decayParas->akaa())
->addTransfer(_catotelm_o, _tempCarbon, (1 - deadPoolTurnoverRate) * decayParas->akco());
_landUnitData->submitOperation(peatlandDeadPoolDecay);
_landUnitData->applyOperations();
}
void PeatlandDecayModule::allocateCh4CO2(double awtd) {
double OptCH4WTD = this->wtdFch4Paras->OptCH4WTD();
double F10d = this->wtdFch4Paras->F10d();
double F10r = this->wtdFch4Paras->F10r();
double FCH4max = this->wtdFch4Paras->FCH4_max();
double ch4Portion = 0.0;
if (OptCH4WTD < awtd) {
ch4Portion = FCH4max * pow(F10r, ((OptCH4WTD - awtd) / 10.0));
}
else {
ch4Portion = FCH4max * pow(F10d, ((OptCH4WTD - awtd) / 10.0));
}
double tempCPoolValue = _tempCarbon->value();
double co2Portion = tempCPoolValue - ch4Portion;
if (tempCPoolValue > 0.0 && co2Portion > 0.0 && ch4Portion > 0.0)
{
auto peatlandDeadPoolDecay = _landUnitData->createStockOperation();
peatlandDeadPoolDecay
->addTransfer(_tempCarbon, _ch4, ch4Portion)
->addTransfer(_tempCarbon, _co2, co2Portion);
_landUnitData->submitOperation(peatlandDeadPoolDecay);
_landUnitData->applyOperations();
}
}
void PeatlandDecayModule::doPeatlandDecay(double deadPoolTurnoverRate, double awtd) {
//special turnover rate for catotelm pool -> (Catotelm *'akc) and (Acrotelm *(1-Pt)*aka
//set zeroTurnoverRate to utilize the getToCO2Rate() and getToCH4Rate() function
double zeroTurnoverRate = 0.0;
auto peatlandDeadPoolDecay = _landUnitData->createProportionalOperation();
peatlandDeadPoolDecay
->addTransfer(_acrotelm_o, _co2, getToCO2Rate(decayParas->aka(), deadPoolTurnoverRate, awtd))
->addTransfer(_acrotelm_o, _ch4, getToCH4Rate(decayParas->aka(), deadPoolTurnoverRate, awtd))
->addTransfer(_acrotelm_a, _co2, getToCO2Rate(decayParas->akaa(), deadPoolTurnoverRate, awtd))
->addTransfer(_acrotelm_a, _ch4, getToCH4Rate(decayParas->akaa(), deadPoolTurnoverRate, awtd))
->addTransfer(_catotelm_a, _co2, getToCO2Rate(decayParas->akc(), zeroTurnoverRate, awtd))
->addTransfer(_catotelm_a, _ch4, getToCH4Rate(decayParas->akc(), zeroTurnoverRate, awtd))
->addTransfer(_catotelm_o, _co2, getToCO2Rate(decayParas->akco(), zeroTurnoverRate, awtd))
->addTransfer(_catotelm_o, _ch4, getToCH4Rate(decayParas->akco(), zeroTurnoverRate, awtd))
->addTransfer(_woodyFoliageDead, _co2, getToCO2Rate((turnoverParas->Pfn() * decayParas->akwfne() + turnoverParas->Pfe() * decayParas->akwfe()), deadPoolTurnoverRate, awtd))
->addTransfer(_woodyFoliageDead, _ch4, getToCH4Rate((turnoverParas->Pfn() * decayParas->akwfne() + turnoverParas->Pfe() * decayParas->akwfe()), deadPoolTurnoverRate, awtd))
->addTransfer(_woodyFineDead, _co2, getToCO2Rate(decayParas->akwsb(), deadPoolTurnoverRate, awtd))
->addTransfer(_woodyFineDead, _ch4, getToCH4Rate(decayParas->akwsb(), deadPoolTurnoverRate, awtd))
->addTransfer(_woodyCoarseDead, _co2, getToCO2Rate(decayParas->akwc(), deadPoolTurnoverRate, awtd))
->addTransfer(_woodyCoarseDead, _ch4, getToCH4Rate(decayParas->akwc(), deadPoolTurnoverRate, awtd))
->addTransfer(_woodyRootsDead, _co2, getToCO2Rate(decayParas->akwr(), deadPoolTurnoverRate, awtd))
->addTransfer(_woodyRootsDead, _ch4, getToCH4Rate(decayParas->akwr(), deadPoolTurnoverRate, awtd))
->addTransfer(_sedgeFoliageDead, _co2, getToCO2Rate(decayParas->aksf(), deadPoolTurnoverRate, awtd))
->addTransfer(_sedgeFoliageDead, _ch4, getToCH4Rate(decayParas->aksf(), deadPoolTurnoverRate, awtd))
->addTransfer(_sedgeRootsDead, _co2, getToCO2Rate(decayParas->aksr(), deadPoolTurnoverRate, awtd))
->addTransfer(_sedgeRootsDead, _ch4, getToCH4Rate(decayParas->aksr(), deadPoolTurnoverRate, awtd))
->addTransfer(_feathermossDead, _co2, getToCO2Rate(decayParas->akfm(), deadPoolTurnoverRate, awtd))
->addTransfer(_feathermossDead, _ch4, getToCH4Rate(decayParas->akfm(), deadPoolTurnoverRate, awtd));
_landUnitData->submitOperation(peatlandDeadPoolDecay);
_landUnitData->applyOperations();
}
double PeatlandDecayModule::getToCH4Rate(double rate, double deadPoolTurnoverRate, double awtd) {
double retVal = 0.0;
retVal = rate * (1 - deadPoolTurnoverRate) * (awtd * decayParas->c() + decayParas->d());
return retVal;
}
double PeatlandDecayModule::getToCO2Rate(double rate, double deadPoolTurnoverRate, double awtd) {
double retVal = 0.0;
retVal = rate * (1 - deadPoolTurnoverRate) * (1 - (awtd * decayParas->c() + decayParas->d()));
return retVal;
}
/**
ToAirTotal =
(D_W_Foliage *(1-Pt)(Pfe*akwfe) + Pfn*akwfne)) +
(D_W_StemsBranches *(1-Pt)*akwsb +
(D_W_Roots *(1-Pt)*akwr +
(D_S_Foliage *(1-Pt)*aksf +
(D_S_Roots *(1-Pt)*aksr +
(D_Feather_Moss *(1-Pt)*akfm +
(Acrotelm *(1-Pt)*aka +
(Catotelm *'akc)
ToCH4 = ToAirTotal * ((c * wtd) + d)
ToCO2 = ToAirTotal - ToCH4
*/
}
}
} // namespace moja::modules::cbm