This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
abiotic.C
324 lines (287 loc) · 8.57 KB
/
abiotic.C
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
// abiotic.C -- Standard abiotic factors.
//
// Copyright 2007 Per Abrahamsen and KVL.
//
// This file is part of Daisy.
//
// Daisy is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// Daisy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser Public License for more details.
//
// You should have received a copy of the GNU Lesser Public License
// along with Daisy; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#define BUILD_DLL
#include "abiotic.h"
#include "mathlib.h"
#include "assertion.h"
#include "block_model.h"
#include "plf.h"
#include "check.h"
#include "function.h"
#include "units.h"
#include "librarian.h"
#include <sstream>
double
Abiotic::f_h (double h)
{
// Used by mineralization and chemical decomposition.
if (h >= 0.0)
return 0.6;
const double pF = h2pF (h);
if (pF <= 0.0)
return 0.6;
if (pF <= 1.5)
return 0.6 + (1.0 - 0.6) * pF / 1.5;
if (pF <= 2.5)
return 1.0;
if (pF <= 6.5)
return 1.0 - (pF - 2.5) / (6.5 - 2.5);
return 0;
}
double
Abiotic::f_T0 (const double T)
{
// Used by mineralization and chemical decomposition.
if (T < 0.0)
return 0.0;
if (T < 20.0)
return 0.1 * T;
if (T < 37.0)
return exp (0.47 - 0.027 * T + 0.00193 * T *T);
if (T < 60.0)
{
// J.A. van Veen and M.J.Frissel.
const double T_max = 37.0;
const double max_val = exp (0.47 - 0.027 * T_max + 0.00193 * sqr (T_max));
return max_val * (1.0 - (T - 37.0) / (60.0 - 37.0));
}
return 0.0;
}
double
Abiotic::f_T2 (const double T)
{
// Used by nitrification and denitrification.
if (T < 2.0)
return 0.0;
if (T < 6.0)
return 0.15 * (T - 2.0);
if (T < 20.0)
return 0.10 * T;
if (T < 37.0)
return exp (0.47 - 0.027 * T + 0.00193 * T * T);
if (T < 60.0)
{
// J.A. van Veen and M.J.Frissel.
const double T_max = 37.0;
const double max_val = exp (0.47 - 0.027 * T_max + 0.00193 * sqr (T_max));
return max_val * (1.0 - (T - 37.0) / (60.0 - 37.0));
}
return 0.0;
}
double
Abiotic::find_T_scale (const BlockModel& al)
{
const double T_ref = al.number ("T_ref");
const PLF& decompose_heat_factor = al.plf ("decompose_heat_factor");
const double ref_value = (decompose_heat_factor.size () < 1)
? Abiotic::f_T0 (T_ref)
: decompose_heat_factor (T_ref);
daisy_assert (ref_value > 0.0);
return 1.0 / ref_value;
}
double
Abiotic::find_SMB_scale (const BlockModel& al)
{
const double SMB_ref = al.number ("SMB_ref", -1.0);
if (SMB_ref < 0.0)
// No scaling.
return 1.0;
const double decompose_SMB_KM = al.number ("decompose_SMB_KM");
const double ref_value = (decompose_SMB_KM > 0.0)
? SMB_ref / (decompose_SMB_KM + SMB_ref)
: 1.0;
daisy_assert (ref_value > 0.0);
return 1.0 / ref_value;
}
static bool
check_alist (const Metalib& metalib, const Frame& al, Treelog& msg)
{
bool ok = true;
// T_ref
const double T_ref = al.number ("T_ref");
const PLF& decompose_heat_factor = al.plf ("decompose_heat_factor");
const double ref_value = (decompose_heat_factor.size () < 1)
? Abiotic::f_T0 (T_ref)
: decompose_heat_factor (T_ref);
if (!(ref_value > 0.0))
{
std::ostringstream tmp;
tmp << "heat_factor at " << T_ref << " dg C (T_ref) is " << ref_value
<< ", should be > 0";
msg.error (tmp.str ());
ok = false;
}
// SMB_ref
if (al.check ("SMB_ref"))
{
const double SMB_ref = al.number ("SMB_ref");
const double decompose_SMB_KM = al.number ("decompose_SMB_KM");
const double ref_value = (decompose_SMB_KM > 0.0)
? SMB_ref / (decompose_SMB_KM + SMB_ref)
: 1.0;
if (!(ref_value > 0.0))
{
std::ostringstream tmp;
tmp << "SMB_factor at " << SMB_ref << " g C/cm^3 is " << ref_value
<< ", should be > 0";
msg.error (tmp.str ());
ok = false;
}
}
return ok;
}
void
Abiotic::load_frame (Frame& frame)
{
frame.add_check (check_alist);
frame.declare ("decompose_heat_factor", "dg C", Attribute::None (),
Attribute::Const, "Heat factor on decomposition.");
frame.set ("decompose_heat_factor", PLF::empty ());
frame.declare ("T_ref", "dg C", Attribute::Const, "\
Reference temperature for decomposition.\n\
The heat factor on decomposition will be scaled so it is 1 at\n\
this temperature..");
frame.set ("T_ref", 10.0);
frame.declare ("decompose_water_factor", "cm", Attribute::None (),
Attribute::Const,
"Water potential factor on decomposition.");
frame.set ("decompose_water_factor", PLF::empty ());
frame.declare_integer ("decompose_SMB_pool", Attribute::Const, "\
SMB pool for Michaelis-Menten kinetics.\n\
Use 0 for SMB1, 1 for SMB2, or -1 for all SMB pools.");
frame.set ("decompose_SMB_pool", 1);
frame.declare ("decompose_SMB_KM", "g C/cm^3", Check::non_negative (),
Attribute::Const, "\
Michaelis-Menten kinetics parameter.\n\
Decompose rate is modified by C / (KM + C), where C is the carbon content\n\
in the pool specified by 'decompose_SMB_pool'.");
frame.set ("decompose_SMB_KM", 0.0);
frame.declare ("SMB_ref", "g C/cm^3", Attribute::OptionalConst, "\
Reference SMB carbon for docomposition of mulch.\n\
The SMB factor for decomposition will be scaled so it is 1 at\n\
this amount of SMB carbon. By default, it will not be scaled.");
}
// The 'T_scale' base model.
struct FunctionTScale : public Function
{
mutable double scale; // []
const double ref; // [dg C]
// Simulation.
virtual double factor (const double T) const = 0;
double value (const double T) const
{
if (scale < 0.0)
{
const double ref_factor = factor (ref);
if (!std::isnormal (ref_factor))
throw "Bad reference temperature";
scale = 1.0 / ref_factor;
daisy_assert (std::isnormal (scale));
}
return factor (T) * scale;
}
// Create.
FunctionTScale (const BlockModel& al)
: Function (al),
scale (-42.42e42),
ref (al.number ("ref"))
{ }
};
static struct FunctionTScaleSyntax : public DeclareBase
{
FunctionTScaleSyntax ()
: DeclareBase (Function::component, "T_scale",
"Scale to reference temperature.")
{ }
void load_frame (Frame& frame) const
{
frame.declare ("ref", "dg C", Attribute::Const, "\
Temperature at which the function is one.");
frame.set ("domain", Units::dgC ());
frame.set ("range", Attribute::None ());
}
} FunctionTScale_syntax;
// The 'T_min' model.
struct FunctionTMin : public FunctionTScale
{
// Simulation.
double factor (const double T) const
{ return Abiotic::f_T0 (T); }
// Create.
FunctionTMin (const BlockModel& al)
: FunctionTScale (al)
{ }
};
static struct FunctionTMinSyntax : public DeclareModel
{
Model* make (const BlockModel& al) const
{ return new FunctionTMin (al); }
FunctionTMinSyntax ()
: DeclareModel (Function::component, "T_min", "T_scale",
"Default temperature function used for mineralization.\n\
Equation (6-13) in A10, with a linear decrease beginning at 37 dg C, down\n\
to 0 at 60 dg C, according to J.A. van Veen and M.J.Frissel.")
{ }
void load_frame (Frame& frame) const
{
frame.set ("ref", 10.0);
frame.set_strings ("cite", "daisy-def");
}
} FunctionTMin_syntax;
// The 'T_min_15' parameterization.
static struct FunctionTMin15Syntax : public DeclareParam
{
FunctionTMin15Syntax ()
: DeclareParam (Function::component, "T_min_15", "T_min",
"T_min normalized to 15 dg C.")
{ }
void load_frame (Frame& frame) const
{
frame.set ("ref", 15.0);
}
} FunctionTMin15_syntax;
// The 'T_nit' model.
struct FunctionTNit : public FunctionTScale
{
// Simulation.
double factor (const double T) const
{ return Abiotic::f_T2 (T); }
// Create.
FunctionTNit (const BlockModel& al)
: FunctionTScale (al)
{ }
};
static struct FunctionTNitSyntax : public DeclareModel
{
Model* make (const BlockModel& al) const
{ return new FunctionTNit (al); }
FunctionTNitSyntax ()
: DeclareModel (Function::component, "T_nit", "T_scale",
"Default temperature function used for nitrification.\n\
Equation (7-3) in A10, with a linear decrease beginning at 37 dg C, down\n\
to 0 at 60 dg C, according to J.A. van Veen and M.J.Frissel.")
{ }
void load_frame (Frame& frame) const
{
frame.set ("ref", 10.0);
frame.set_strings ("cite", "daisy-def");
}
} FunctionTNit_syntax;
// abiotic.C ends here.