LandscapeDNDC 1.37.0
soilchemistry-metrx.h
1
2#ifndef LM_SOILCHEMISTRYMETRX_H_
3#define LM_SOILCHEMISTRYMETRX_H_
4
5#include "mbe_legacymodel.h"
6#include "state/mbe_state.h"
7#include "ld_shared.h"
8
9#include "models/soilchemistry/metrx/output-soilchemistry-metrx.h"
10#include "models/soilchemistry/metrx/soilchemistry-metrx.h.inc"
11#include "models/soilchemistry/ld_transport.h"
12#include "models/soilchemistry/ld_enhanced_efficiency_nitrogen_fertilizers.h"
13
14#include "eventhandler/fertilize/fertilize.h"
15#include "eventhandler/till/till.h"
16
17#include <math/lmath-tdma.h>
18#include <logging/cbm_logging.h>
19
20namespace ldndc {
21
22extern cbm::logger_t * SoilChemistryMeTrXLogger;
23
28class LDNDC_API SoilChemistryMeTrX : public MBE_LegacyModel
29{
31 static const double TNORM;
32
34 static const double C_SATURATION;
35
36 LMOD_EXPORT_MODULE_INFO(SoilChemistryMeTrX,"soilchemistry:metrx","Soilchemistry MeTrX");
37public:
39 MoBiLE_State *,
40 cbm::io_kcomm_t *,
41 timemode_e);
42
44
45 lerr_t configure( ldndc::config_file_t const *);
46 lerr_t register_ports( cbm::io_kcomm_t *);
47 lerr_t initialize();
48
49 lerr_t solve();
50 lerr_t integrate();
51
52 lerr_t unregister_ports( cbm::io_kcomm_t *);
53 lerr_t finalize();
54
55 lerr_t sleep() { return LDNDC_ERR_OK; }
56 lerr_t wake() { return LDNDC_ERR_OK; }
57
58private:
59 cbm::io_kcomm_t * io_kcomm;
60
61 input_class_groundwater_t const * gw_;
62 input_class_siteparameters_t const & sipar_;
63 input_class_soillayers_t const & sl_;
64 input_class_setup_t const & se_;
65
66 substate_surfacebulk_t & sb_;
67 substate_airchemistry_t & ac_;
68
69 substate_microclimate_t const & mc_;
70 substate_physiology_t & ph_;
71 substate_soilchemistry_t & sc_;
72 substate_watercycle_t & wc_;
73
74 MoBiLE_PlantVegetation * m_veg;
75
76 SubscribedEvent<LD_EventHandlerQueue> m_FertilizeEvents;
77 SubscribedEvent<LD_EventHandlerQueue> m_IrrigationEvents;
78 SubscribedEvent<LD_EventHandlerQueue> m_ManureEvents;
79 SubscribedEvent<LD_EventHandlerQueue> m_PlantEvents;
80 SubscribedEvent<LD_EventHandlerQueue> m_TillEvents;
81
82 Transport transport_;
83 ControlledReleaseNitrogenFertilizer crnf_;
84
85 timemode_e const timemode_;
86
87 OutputSoilchemistryMeTrX output_writer_;
88 ldndc_flt64_t * output_data_;
89
90 int const TOTAL_TIME_STEPS;
91 int const INTERNAL_TIME_STEPS;
92 double const FTS_TOT_;
93
94 /* Molar weights scaled from [g mol-1] to [kg mol-1] */
95
96 double const M_C_SCALE; // Molar weigth of C [kg mol-1]
97 double const M_2C_SCALE; // Molar weigth of C [kg mol-1]
98 double const M_N_SCALE; // Molar weigth of N [kg mol-1]
99 double const M_2H_SCALE; // Molar weigth of H2 [kg mol-1]
100 double const M_2N_SCALE; // Molar weigth of N2 [kg mol-1]
101 double const M_O_SCALE; // Molar weigth of O2 [kg mol-1]
102 double const M_2O_SCALE; // Molar weight of SO4 in [kg mol-1]
103 double const M_FE_SCALE; // Molar weight of Fe in [kg mol-1]
104
105 double const N_O2_RATIO_NITRIFICATION;
106 double const ACETATE_RATIO_FERM_SYN; // Ratio of acetate production from glucose via fermentative/syntrophic pathway. [-]
107
108 double const H2_MOL_CH4_KG_CONVERSION; // Converts from mol H2 consumed for CH4 production to kg CO2 needed
109 double const H2_KG_CH4_KG_CONVERSION; // Converts from kg H2 consumed for CH4 production to kg CO2 needed
110 double const H2_KG_CH4_MOL_CONVERSION; // Converts from kg H2 consumed for CH4 production to mol CO2 needed
111
112 double const FE3_ACETATE_REDUCTION_RATIO; // CHCOO(-) + 8Fe(3+) + 4 H2O -> 2 HCO3(-) + 8 Fe(2+) + 9 H(+) (Brock Biology of Microorganisms)
113 double const FE3_HYDROGEN_REDUCTION_RATIO; // H2 + 2 Fe(3+) + 4 H+ -> 2 Fe2+ + 6 H2O
114
115 double const O2_CONVERSION_FOR_CH4_OX;
116
117 double const NO3_MOLAR_MAX_FE_RED; // NO3-threshold concentration. No Fe3-reduction possible for no3 > NO3_MOLAR_MAX_FE_RED. [mol m-3]
118 double const FE3_MOLAR_MAX_CH4_PROD; // Fe3-threshold concentration. No CH4-production possible for fe3 > FE3_MOLAR_MAX_CH4_PROD. [mol m-3]
119 double const O2_FE2_RATIO; // 2 Fe(2+) + 0.5 O2 + 2 H(+) -> 2 Fe(3+) + H2O
120
121 double const MICRO_C_MIN;
122
123 double const MC_MO2_RATIO; // Factor that transforms O2-consumption to CO2-production
124 double const RGAS_M_O2_BAR_PA; // Conversion factor for anaerobic volume calculation.
125
126 double const K_HU_DOC;
127
128 double const K_DC_AORG;
129 double const K_HU_AORG_HUM1;
130 double const K_HU_AORG_HUM2;
131
132 double const K_DC_SOL;
133 double const K_HU_SOL;
134
135 double const K_DC_CEL;
136 double const K_HU_CEL;
137
138 double const K_DC_LIG;
139 double const K_HU_LIG;
140
141 double const K_DC_HUM1;
142 double const K_HU_HUM1;
143
144 double const K_DC_HUM2;
145 double const K_HU_HUM2;
146
147 double const K_DC_HUM3;
148 double const KR_DENIT_CHEMO;
149
150 double const K_FRAG_STUBBLE;
151 double const K_FRAG_ALGAE;
152 double const K_FRAG_RAW_LITTER;
153 double const K_FRAG_WOOD;
154
155 double const KMM_O2_ROOT_RESPIRATION;
156
157 double const MUE_MAX_C_MICRO_1; // Maximal microbial growth rate for mic_1. [kg C timestep-1]
158 double const MUE_MAX_C_MICRO_2; // Maximal microbial growth rate for mic_2. [kg C timestep-1]
159 double const MUE_MAX_C_MICRO_3; // Maximal microbial growth rate for mic_3. [kg C timestep-1]
160
161 double const METRX_MUEMAX_C_CH4_PROD;
162 double const METRX_MUEMAX_H2_CH4_PROD;
163 double const METRX_MUEMAX_C_CH4_OX_HA;
164 double const METRX_MUEMAX_C_CH4_OX_LA;
165
166 double const METRX_MUEMAX_C_FE_RED;
167 double const METRX_KR_OX_FE;
168
169 double const MUE_MAX_N_ASSI;
170
171 double const PH_SURFACE_WATER;
172 double const PH_MAX;
173
174 double const A_MAX_ALGAE;
175 double const A_MAX_MICRO_1;
176 double const A_MAX_MICRO_2;
177 double const A_MAX_MICRO_3;
178
179 double const METRX_F_DENIT_N2_MIN;
180 double const METRX_F_DENIT_N2_DELTA;
181
182 double const D_NO_WATER_SCALE;
183 double const D_N2O_WATER_SCALE;
184 double const D_O2_WATER_SCALE;
185 double const D_CO2_WATER_SCALE;
186 double const D_CH4_WATER_SCALE;
187 double const D_NH3_WATER_SCALE;
188 double const D_NH4_WATER_SCALE;
189 double const D_NO3_WATER_SCALE;
190 double const D_NO2_WATER_SCALE;
191 double const D_DOC_WATER_SCALE;
192
193 double const D_O2_AIR_SCALE;
194 double const D_N2_AIR_SCALE;
195 double const D_N2O_AIR_SCALE;
196 double const D_NO_AIR_SCALE;
197 double const D_CH4_AIR_SCALE;
198 double const D_CO2_AIR_SCALE;
199 double const D_NH3_AIR_SCALE;
200 double const D_RADON_AIR_SCALE;
201
202 double const METRX_V_EBULLITION;
203 double const GROUNDWATER_NUTRIENT_ACCESS_RATE;
204
205 size_t SL_SURFACE_DISTRIBUTION; // number of soil layers for surface matter allocation to soil domaine
206 double SL_SURFACE_DISTRIBUTION_INVERSE; // inverse of SL_SURFACE_DISTRIBUTION
207
208 //wind speed
209 double const *mc_wind;
210
211 // soil temperature
212 double const *mc_temp_atm;
213 lvector_t< double > const &mc_temp_sl;
214
215 // water flux
216 double *waterflux_sl;
217 double *accumulated_waterflux_old_sl;
218
219 // infiltration flux
220 double infiltration;
221 double accumulated_infiltration_old;
222
223private:
224
225 PublishedField<double> StubbleCarbon;
226
227 /*****/
228 /* */
229 /*****/
230
231 bool peat_dev;
232 bool have_algae;
233 bool have_dry_wet;
234 cbm::string_t freeze_thaw_method;
235 bool have_surface_bulk;
236 bool have_canopy_transport;
237 bool have_river_connection;
238 bool have_litter_height_change;
239 cbm::string_t d_eff_method;
240 bool have_radon_diffusion;
241 double spinup_delta_c;
242 double spinup_delta_c_depth;
243
244 cbm::string_t anvf_method;
245
246 bool have_plant_diffusion;
247 bool have_water_table; // True for timespan with surface water
248
249 double h_wl; // heigth of each watertable layer [m]
250
251 double c_algae;
252 double c_dead_algae;
253 double n_algae;
254 double n_dead_algae;
255
256 double *o2_concentration;
257 lvector_t< double > ts_co2_concentration_fl;
258 lvector_t< double > ts_ch4_concentration_fl;
259 lvector_t< double > ts_no_concentration_fl;
260 lvector_t< double > ts_radon_concentration_fl;
261 lvector_t< double > nh3_fl;
262
263 /*********************/
264 /* balance variables */
265 /*********************/
266
267 double tot_c_balance_1;
268 double tot_n_balance_1;
269
270 /************************/
271 /* daily rate variables */
272 /************************/
273
274 // Groundwater access
275 double day_no3_groundwater_access;
276
277 // Mineralisation
278 double day_min_n_decomp;
279 double day_min_n_aorg;
280 double day_min_n_mic_1;
281 double day_min_n_mic_2;
282 double day_min_n_mic_3;
283
284 // Assimilation
285 double day_assi_n_mic_1;
286 double day_assi_n_mic_2;
287 double day_assi_n_mic_3;
288 double day_assi_c_mic_1;
289 double day_assi_c_mic_2;
290 double day_assi_c_mic_3;
291
292 // Nitrification
293 double day_nit_nh4_no2;
294 double day_nit_no2_no;
295 double day_nit_no2_n2o;
296
297 // Denitrification
298 double day_denit_no3_no2;
299 double day_denit_no2_no;
300 double day_denit_no2_n2o;
301 double day_denit_no2_n2;
302 double day_denit_no_n2o;
303 double day_denit_no_n2;
304 double day_denit_n2o_n2;
305 double day_chemodenit_no2_no;
306
307 // Respiration / Fermentation / Methanogenesis
308 double day_co2_prod_mic_1_growth;
309 double day_co2_prod_mic_1_maintenance;
310 double day_co2_prod_mic_2;
311 double day_co2_prod_mic_3_acetate_prod;
312 double day_co2_prod_mic_3_acetate_cons;
313 double day_co2_prod_ch4_prod;
314 double day_co2_prod_ch4_cons;
315
316 // Leaching
317 double day_leach_o2;
318 double day_leach_n2o;
319 double day_leach_n2;
320 double day_leach_no;
321 double day_leach_nh3;
322 double day_leach_urea;
323 double day_leach_radon;
324
325 // litter and algae
326 double accumulated_c_litter_above_old;
327 double accumulated_c_litter_below_old;
328
329 double dC_root_exsudates;
330 double dC_litter_algae;
331
332 // Decomposition
333 double day_decomp_c_lit_1;
334 double day_decomp_c_lit_2;
335 double day_decomp_c_lit_3;
336 double day_decomp_n_lit_1;
337 double day_decomp_n_lit_2;
338 double day_decomp_n_lit_3;
339 lvector_t< double > day_decomp_c_hum_1_sl;
340 lvector_t< double > day_decomp_c_hum_2_sl;
341 lvector_t< double > day_decomp_c_hum_3_sl;
342 lvector_t< double > day_decay_c_mic_sl;
343 double day_decomp_n_hum_1;
344 double day_decomp_n_hum_2;
345 double day_decomp_n_hum_3;
346
347 // Humification
348 lvector_t< double > day_c_humify_doc_hum_2_sl;
349 lvector_t< double > day_c_humify_sol_hum_1_sl;
350 lvector_t< double > day_c_humify_cel_hum_1_sl;
351 lvector_t< double > day_c_humify_lig_hum_1_sl;
352 lvector_t< double > day_c_humify_lig_hum_2_sl;
353 lvector_t< double > day_c_humify_mic_hum_1_sl;
354 lvector_t< double > day_c_humify_mic_hum_2_sl;
355 lvector_t< double > day_c_humify_hum_1_hum_2_sl;
356 lvector_t< double > day_c_humify_hum_2_hum_3_sl;
357
358 // Algae
359 double day_n_fix_algae;
360 double day_c_fix_algae;
361
362 // DOC production
363 double day_doc_prod_decomp_litter; // daily doc production by litter decomposition
364 double day_doc_prod_decomp_humus; // daily doc production by humus decomposition
365 double day_doc_prod_decomp_aorg; // daily doc production by active organic material decomposition
366
367
368 /*****************************/
369 /* Litter C- and N-fractions */
370 /*****************************/
371
372 enum atm_eq_liq{ nh3_atm_eq_liq, o2_atm_eq_liq, co2_atm_eq_liq, ch4_atm_eq_liq, n2o_atm_eq_liq, no_atm_eq_liq, radon_atm_eq_liq };
373
374 size_t subdaily_time_step_;
375
376 // Respiration
377 lvector_t< double > co2_auto_sl;
378 lvector_t< double > co2_hetero_sl;
379
380 lvector< double > cn_hum_1_sl;
381 lvector< double > cn_hum_2_sl;
382 lvector< double > cn_hum_3_sl;
383
384 lvector< double > freeze_thaw_fact_sl;
385 lvector< double > litter_type_fact_sl;
386
387 // Iron, sulfate, ...
388 lvector_t< double > day_acetate_cons_fe3_sl;
389 lvector_t< double > day_h2_c_eq_cons_fe3_sl;
390 lvector_t< double > day_fe2_oxidation_sl;
391
392 // Nitrification
393 lvector_t< double > day_nitrify_n2o_sl;
394 lvector_t< double > day_nit_no2_no3_sl;
395
396 // Microbes
397 lvector_t< double > cn_opt_mic_sl;
398
399 // Pool variables
400 lvector_t< double > h2_sl;
401
402 lvector_t< double > o2_liq_sl;
403 lvector_t< double > o2_gas_sl;
404 lvector_t< double > o2_consumption_sl;
405
406 lvector_t< double > ae_acetate_sl;
407 lvector_t< double > an_acetate_sl;
408
409 lvector_t< double > ch4_liq_sl;
410 lvector_t< double > ch4_gas_sl;
411 lvector_t< double > co2_liq_sl;
412 lvector_t< double > co2_gas_sl;
413
414 lvector_t< double > nh4_ae_sl;
415 lvector_t< double > nh4_an_sl;
416
417 lvector_t< double > don_ae_sl;
418 lvector_t< double > don_an_sl;
419
420 lvector_t< double > no3_ae_sl;
421 lvector_t< double > no3_an_sl;
422
423 lvector_t< double > doc_ice_sl;
424 lvector_t< double > acetate_ice_sl;
425 lvector_t< double > no3_ice_sl;
426 lvector_t< double > nh4_ice_sl;
427 lvector_t< double > don_ice_sl;
428
429 lvector_t< double > n2o_liq_sl;
430 lvector_t< double > n2o_gas_sl;
431 lvector_t< double > an_n2o_liq_sl;
432 lvector_t< double > an_n2o_gas_sl;
433 lvector_t< double > n2_gas_sl;
434
435 lvector_t< double > no_liq_sl;
436 lvector_t< double > no_gas_sl;
437 lvector_t< double > an_no_liq_sl;
438 lvector_t< double > an_no_gas_sl;
439
440 lvector_t< double > radon_liq_sl;
441 lvector_t< double > radon_gas_sl;
442
443 lvector_t< double > c_microbial_necromass_sl; // carbon content of microbial necromass
444 lvector_t< double > n_microbial_necromass_sl; // nitrogen content of microbial necromass
445
446 lvector_t< double > c_humus_1_sl; // carbon content of humus_0 pool
447 lvector_t< double > c_humus_2_sl; // carbon content of humus_1 pool
448 lvector_t< double > c_humus_3_sl; // carbon content of humus_2 pool
449
450 lvector_t< double > n_humus_1_sl; // nitrogen content of humus_0 pool
451 lvector_t< double > n_humus_2_sl; // nitrogen content of humus_1 pool
452 lvector_t< double > n_humus_3_sl; // nitrogen content of humus_2 pool
453
454 lvector_t< double > n_micro_1_sl; // nitrogen content of micro_1 pool
455 lvector_t< double > n_micro_2_sl; // nitrogen content of micro_2 pool
456 lvector_t< double > n_micro_3_sl; // nitrogen content of micro_3 pool
457
458
459 // Diffusion
460 lvector_t< double > D_eff_air_fl; // Effective gas diffusion coefficient in atmosphere.
461 lvector_t< double > D_eff_air_sl; // Effective gas diffusion coefficient in soils after WARRICK.
462 lvector_t< double > D_eff_water_sl;
463 lvector_t< double > D_eff_dailyturbation_sl;
464 lvector_t< double > D_eff_plant_sl; // Effective O2 diffusion coefficient in plants
465
466 lvector_t< double > interface_air_sl; // interface of air content between two soil layers
467 lvector_t< double > interface_delta_x_air_sl; // interface of air content between two soil layers divided by distance
468 lvector_t< double > interface_delta_x_water_sl; // interface of water content between two soil layers divided by distance
469 lvector_t< double > interface_delta_x_soil_sl;
470
471 lvector_t< double > delta_x; // interface of water content between two soil layers
472 lvector_t< double > pore_connectivity_sl; // connectivity of pores
473
474 // Soil environment
475 double ph_delta_pab_wl;
476 double ph_delta_urea_wl;
477
478 lvector_t< double > ph_delta_urea_sl;
479
480 lvector_t< double > soil_gas_advection_sl; // soil gas advection [m:s-1]
481 lvector_t< double > v_water_sl; // water volume of soillayer [m3]
482 lvector_t< double > v_air_sl; // air volume of soillayer [m3]
483 lvector_t< double > v_ice_sl; // ice volume of soillayer [m3]
484
485 lvector_t< double > communicate_sl;
486 lvector_t< double > communicate_fsl;
487 lvector_t< double > day_denit_factor_c_sl;
488 lvector_t< double > day_denit_factor_n_sl;
489
490 // Methanogenesis
491 lvector_t< double > day_ch4_production_hydrogen_sl;
492 lvector_t< double > day_ch4_production_acetate_sl;
493 lvector_t< double > day_ch4_oxidation_sl; // Layerspecific daily CH4-Oxidation in soil. [kg C-CH4 day-1]
494
495 lvector< double > subdaily_ch4_bubbling; // Subdaily CH4 emission rate via bubbling. [kg C m-2 timestep-1]
496 lvector< double > subdaily_ch4_plant; // Subdaily CH4 emission rate via plant diffusion. [kg C m-2 timestep-1]
497 lvector< double > subdaily_ch4_soil; // Subdaily CH4 emission rate via soil diffusion. [kg C m-2 timestep-1]
498 lvector< double > subdaily_ch4_water; // Subdaily CH4 emission rate via water table diffusion. [kg C m-2 timestep-1]
499
500 lvector< double > subdaily_ch4_leach; // Subdaily CH4 leaching rate. [kg C m-2 timestep-1]
501 lvector< double > subdaily_ch4_prod; // Subdaily CH4 production rate. [kg C m-2 timestep-1]
502 lvector< double > subdaily_ch4_ox; // Subdaily CH4 oxidation rate. [kg C m-2 timestep-1]
503 lvector< double > subdaily_ch4_content; // Subdaily CH4 oxidation rate. [kg C m-2 timestep-1]
504
505 lvector< double > subdaily_co2_bubbling; // Subdaily CH4 emission rate via bubbling. [kg C m-2 timestep-1]
506 lvector< double > subdaily_co2_plant; // Subdaily CH4 emission rate via plant diffusion. [kg C m-2 timestep-1]
507 lvector< double > subdaily_co2_soil; // Subdaily CH4 emission rate via soil diffusion. [kg C m-2 timestep-1]
508 lvector< double > subdaily_co2_water; // Subdaily CH4 emission rate via water table diffusion. [kg C m-2 timestep-1]
509 lvector< double > subdaily_co2_leach; // Subdaily CH4 leaching rate. [kg C m-2 timestep-1]
510
511 // Others
512 lvector< double > subdaily_acetate_prod;
513 lvector< double > subdaily_doc_prod;
514
515 lvector< double > subdaily_o2_bubbling;
516 lvector< double > subdaily_o2_plant;
517 lvector< double > subdaily_o2_soil;
518 lvector< double > subdaily_o2_water;
519
520 lvector< double > subdaily_n2o_bubbling;
521 lvector< double > subdaily_n2o_plant;
522 lvector< double > subdaily_n2o_soil;
523 lvector< double > subdaily_n2o_water;
524
525 lvector< double > subdaily_no_bubbling;
526 lvector< double > subdaily_no_plant;
527 lvector< double > subdaily_no_soil;
528 lvector< double > subdaily_no_water;
529
530 lvector< double > subdaily_nh3_bubbling;
531 lvector< double > subdaily_nh3_plant;
532 lvector< double > subdaily_nh3_soil;
533 lvector< double > subdaily_nh3_water;
534
535 lvector< double > subdaily_plant_o2_cons;
536 lvector< double > subdaily_flood_o2_conc;
537 lvector< double > subdaily_algae_o2_prod;
538
539 lvector< double > subdaily_radon_soil;
540 lvector< double > subdaily_radon_plant;
541 lvector< double > subdaily_radon_water;
542
543 lvector< double > day_doc_prod_sl;
544 lvector< double > day_acetate_prod_sl;
545 lvector< double > day_h2_c_eq_prod_sl;
546
547 lvector< double > plant_o2_consumption_sl; // O2 consumption of oxygen per time step. [kg O2 m-2]
548
549 lvector< double > accumulated_n_nh4_throughfall_sl;
550 lvector< double > accumulated_n_no3_throughfall_sl;
551 lvector< double > accumulated_n_nh4_throughfall_sbl;
552 lvector< double > accumulated_n_no3_throughfall_sbl;
553 double accumulated_n_nh4_throughfall_old;
554 double accumulated_n_no3_throughfall_old;
555
556 // N by planting and fixation
557 lvector< double > accumulated_n_to_living_plant_and_algae_from_extern_sl;
558
559 lvector< double > accumulated_n_algae_nh4_uptake_sbl;
560 lvector< double > accumulated_n_algae_no3_uptake_sbl;
561 lvector< double > accumulated_n_algae_nh3_uptake_sbl;
562
563 lvector< double > accumulated_n_litter_from_plants_below_rawlitter_sl;
564 lvector< double > accumulated_n_litter_from_plants_below_wood_sl;
565 double accumulated_n_litter_from_plants_above_rawlitter;
566 double accumulated_n_litter_from_plants_above_wood;
567 double accumulated_n_litter_from_plants_above_stubble;
568 lvector< double > accumulated_n_aboveground_raw_litter_fragmentation_sl;
569 lvector< double > accumulated_n_belowground_raw_litter_fragmentation_sl;
570 lvector< double > accumulated_n_litter_from_algae_sl;
571 lvector< double > accumulated_n_litter_from_dung_sl;
572 lvector< double > accumulated_n_urea_from_dung_sl;
573
574 double accumulated_n_export_harvest_cutting_grazing;
575 double accumulated_n_export_harvest_old;
576 double accumulated_c_litter_wood_above_old;
577
578 lvector< double > accumulated_n_nh4_fertilization_sl;
579 lvector< double > accumulated_n_no3_fertilization_sl;
580 lvector< double > accumulated_n_nh3_fertilization_sl;
581 lvector< double > accumulated_n_don_fertilization_sl;
582 lvector< double > accumulated_n_urea_fertilization_sl;
583 lvector< double > accumulated_n_litter_fertilization_sl;
584 lvector< double > accumulated_n_aorg_fertilization_sl;
585 lvector< double > accumulated_n_nh4_fertilization_sbl;
586 lvector< double > accumulated_n_no3_fertilization_sbl;
587 lvector< double > accumulated_n_nh3_fertilization_sbl;
588 lvector< double > accumulated_n_urea_fertilization_sbl;
589
590 lvector< double > accumulated_n_surface_litter_incorporation_via_tilling_sl;
591 lvector< double > accumulated_n_litter_tilling_sl;
592 lvector< double > accumulated_n_aorg_tilling_sl;
593 lvector< double > accumulated_n_humus_1_tilling_sl;
594 lvector< double > accumulated_n_humus_2_tilling_sl;
595 lvector< double > accumulated_n_humus_3_tilling_sl;
596 lvector< double > accumulated_n_no3_tilling_sl;
597 lvector< double > accumulated_n_no2_tilling_sl;
598 lvector< double > accumulated_n_no_tilling_sl;
599 lvector< double > accumulated_n_n2o_tilling_sl;
600 lvector< double > accumulated_n_urea_tilling_sl;
601 lvector< double > accumulated_n_don_tilling_sl;
602 lvector< double > accumulated_n_nh4_tilling_sl;
603 lvector< double > accumulated_n_nh3_tilling_sl;
604 lvector< double > accumulated_n_microbes_tilling_sl;
605
606 lvector< double > accumulated_n_humus_1_spinup_sl;
607 lvector< double > accumulated_n_humus_2_spinup_sl;
608 lvector< double > accumulated_n_humus_3_spinup_sl;
609 lvector< double > accumulated_n_surface_litter_spinup_sl;
610 lvector< double > accumulated_n_litter_spinup_sl;
611
612 lvector< double > accumulated_n_urea_nh4_hydrolysis_sl;
613 lvector< double > accumulated_n_urea_nh4_hydrolysis_sbl;
614
615 lvector< double > accumulated_n_nh4_assimilation_sl;
616 lvector< double > accumulated_n_no3_assimilation_sl;
617 lvector< double > accumulated_n_don_assimilation_sl;
618
619 lvector< double > accumulated_n_nh4_nh3_conversion_sl;
620 lvector< double > accumulated_n_nh3_nh4_conversion_sl;
621 lvector< double > accumulated_n_nh4_nh3_conversion_sbl;
622 lvector< double > accumulated_n_nh3_nh4_conversion_sbl;
623
624 lvector< double > accumulated_n_micro_leaching_sl;
625 lvector< double > accumulated_n_aorg_leaching_sl;
626 lvector< double > accumulated_n_litter_leaching_sl;
627 lvector< double > accumulated_n_humus_1_leaching_sl;
628 lvector< double > accumulated_n_humus_2_leaching_sl;
629 lvector< double > accumulated_n_humus_3_leaching_sl;
630 lvector< double > accumulated_n_nh4_leaching_sl;
631 lvector< double > accumulated_n_nh3_leaching_sl;
632 lvector< double > accumulated_n_don_leaching_sl;
633 lvector< double > accumulated_n_urea_leaching_sl;
634 lvector< double > accumulated_n_no_leaching_sl;
635 lvector< double > accumulated_n_n2o_leaching_sl;
636
637 lvector< double > accumulated_n_urea_liq_diffusion_sl;
638 lvector< double > accumulated_n_nh3_liq_diffusion_sl;
639 lvector< double > accumulated_n_nh4_liq_diffusion_sl;
640 lvector< double > accumulated_n_no3_liq_diffusion_sl;
641
642 lvector< double > accumulated_n_nh4_infiltration_phys_sl;
643 lvector< double > accumulated_n_nh3_infiltration_phys_sl;
644 lvector< double > accumulated_n_urea_infiltration_phys_sl;
645 lvector< double > accumulated_n_no3_infiltration_phys_sl;
646 lvector< double > accumulated_n_don_infiltration_phys_sl;
647 lvector< double > accumulated_n_aorg_infiltration_phys_sl;
648
649 lvector< double > accumulated_n_nh4_infiltration_leach_sl;
650 lvector< double > accumulated_n_nh3_infiltration_leach_sl;
651 lvector< double > accumulated_n_urea_infiltration_leach_sl;
652 lvector< double > accumulated_n_no3_infiltration_leach_sl;
653 lvector< double > accumulated_n_don_infiltration_leach_sl;
654 lvector< double > accumulated_n_no_infiltration_leach_sl;
655 lvector< double > accumulated_n_n2o_infiltration_leach_sl;
656
657 lvector< double > accumulated_n_nh4_infiltration_liqdif_sl;
658 lvector< double > accumulated_n_nh3_infiltration_liqdif_sl;
659 lvector< double > accumulated_n_urea_infiltration_liqdif_sl;
660 lvector< double > accumulated_n_no3_infiltration_liqdif_sl;
661
662 lvector< double > accumulated_c_ch4_bubbling_sl;
663 lvector< double > accumulated_c_ch4_bubbling_sbl;
664
665 lvector< double > accumulated_n_nh3_bubbling_sl;
666 lvector< double > accumulated_n_no_bubbling_sl;
667 lvector< double > accumulated_n_n2o_bubbling_sl;
668 lvector< double > accumulated_n_nh3_bubbling_sbl;
669 lvector< double > accumulated_n_no_bubbling_sbl;
670 lvector< double > accumulated_n_n2o_bubbling_sbl;
671
672 lvector< double > accumulated_n_nh3_dissolution_sbl;
673 lvector< double > accumulated_n_no_dissolution_sbl;
674 lvector< double > accumulated_n_n2o_dissolution_sbl;
675
676 lvector< double > accumulated_n_nh3_phys_diffusion_sl;
677 lvector< double > accumulated_n_no_phys_diffusion_sl;
678 lvector< double > accumulated_n_n2o_phys_diffusion_sl;
679 lvector< double > accumulated_n_nh3_gas_diffusion_sl;
680 lvector< double > accumulated_n_no_gas_diffusion_sl;
681 lvector< double > accumulated_n_n2o_gas_diffusion_sl;
682
683 lvector< double > accumulated_n_micro_perturbation_sl;
684 lvector< double > accumulated_n_aorg_perturbation_sl;
685 lvector< double > accumulated_n_litter_perturbation_sl;
686 lvector< double > accumulated_n_humus_1_perturbation_sl;
687 lvector< double > accumulated_n_humus_2_perturbation_sl;
688 lvector< double > accumulated_n_humus_3_perturbation_sl;
689
690 lvector< double > accumulated_n_nh4_no2_nitrification_sl;
691 lvector< double > accumulated_n_nh4_no_nitrification_sl;
692 lvector< double > accumulated_n_nh4_n2o_nitrification_sl;
693 lvector< double > accumulated_n_no2_no3_nitrification_sl;
694
695 lvector< double > accumulated_n_no3_no2_denitrification_sl;
696 lvector< double > accumulated_n_no3_no_denitrification_sl;
697 lvector< double > accumulated_n_no3_n2o_denitrification_sl;
698 lvector< double > accumulated_n_no3_n2_denitrification_sl;
699 lvector< double > accumulated_n_no2_no_denitrification_sl;
700 lvector< double > accumulated_n_no2_n2o_denitrification_sl;
701 lvector< double > accumulated_n_no2_n2_denitrification_sl;
702 lvector< double > accumulated_n_no_n2o_denitrification_sl;
703 lvector< double > accumulated_n_no_n2_denitrification_sl;
704 lvector< double > accumulated_n_n2o_n2_denitrification_sl;
705
706 lvector< double > accumulated_n_no2_chemodenitrification_sl;
707
708 lvector< double > accumulated_n_mic_naorg_decay_sl;
709 lvector< double > accumulated_n_mic_nh4_mineral_sl;
710 lvector< double > accumulated_n_mic_don_dissolve_sl;
711
712 lvector< double > accumulated_n_aorg_nh4_mineral_sl;
713 lvector< double > accumulated_n_aorg_don_dissolve_sl;
714
715 lvector< double > accumulated_n_humus_1_don_dissolve_sl;
716 lvector< double > accumulated_n_humus_1_nh4_mineral_sl;
717 lvector< double > accumulated_n_humus_2_don_dissolve_sl;
718 lvector< double > accumulated_n_humus_2_nh4_mineral_sl;
719 lvector< double > accumulated_n_humus_3_don_dissolve_sl;
720 lvector< double > accumulated_n_humus_3_nh4_mineral_sl;
721
722 lvector< double > accumulated_n_litter_don_dissolve_sl;
723 lvector< double > accumulated_n_litter_nh4_mineral_sl;
724
725 lvector< double > accumulated_n_don_humus_1_humify_sl;
726 lvector< double > accumulated_n_don_humus_2_humify_sl;
727 lvector< double > accumulated_n_don_humus_3_humify_sl;
728 lvector< double > accumulated_n_litter_humus_1_humify_sl;
729
730 lvector< double > accumulated_c_root_exsudates_old_sl;
731
732 lvector_t< double > ranvf_sl;
733 lvector_t< double > cumulative_freezing_degree_days_sl;
734 lvector_t< double > cfdd_turnover_sl;
735
736#ifdef METRX_ANVF_TYPES
737 lvector_t< double > anvf_pnet_sl;
738 lvector_t< double > anvf_dndccan_sl;
739 lvector_t< double > anvf_nloss_sl;
740#endif
741
742 class SpinUp
743 {
744 public:
745
746 SpinUp( size_t _y, size_t _sl_cnt) : spinup_type_( 0),
747 spinup_years_( 0),
748 executed_months_( 0),
749 execute_( false),
750 c_to_humus_1_sl( _sl_cnt, 0.0),
751 c_to_humus_2_sl( _sl_cnt, 0.0),
752 c_to_humus_3_sl( _sl_cnt, 0.0),
753 humify_humus_1_to_humus_2_sl( _sl_cnt, 0.0),
754 humify_humus_2_to_humus_3_sl( _sl_cnt, 0.0),
755 decompose_hum_1( _sl_cnt, 0.0),
756 decompose_hum_2( _sl_cnt, 0.0),
757 decompose_hum_3( _sl_cnt, 0.0),
758
759 loose_lit_1( _sl_cnt, 0.0),
760 loose_lit_2( _sl_cnt, 0.0),
761 loose_lit_3( _sl_cnt, 0.0),
762
763 c_to_lit_1( _sl_cnt, 0.0),
764 c_to_lit_2( _sl_cnt, 0.0),
765 c_to_lit_3( _sl_cnt, 0.0),
766
767 loose_aorg( _sl_cnt, 0.0),
768 c_to_aorg( _sl_cnt, 0.0),
769
770 c_humus_1_temp_sl( _sl_cnt, 0.0),
771 c_humus_2_temp_sl( _sl_cnt, 0.0),
772 c_humus_3_temp_sl( _sl_cnt, 0.0),
773
774 c_litter_1_temp_sl( _sl_cnt, 0.0),
775 c_litter_2_temp_sl( _sl_cnt, 0.0),
776 c_litter_3_temp_sl( _sl_cnt, 0.0),
777
778 n_litter_1_temp_sl( _sl_cnt, 0.0),
779 n_litter_2_temp_sl( _sl_cnt, 0.0),
780 n_litter_3_temp_sl( _sl_cnt, 0.0),
781
782 c_aorg_temp_sl( _sl_cnt, 0.0),
783 n_aorg_temp_sl( _sl_cnt, 0.0),
784
785 cn_humus_2_temp_sl( _sl_cnt, 0.0),
786 cn_humus_3_temp_sl( _sl_cnt, 0.0),
787
788 exit_wood( 0.0),
789 enter_wood( 0.0)
790 {
791 this->set_spinup_years( _y);
792 }
793
794 ~SpinUp()
795 {}
796
797 public:
798
799 void reset( bool _reset_litter = true)
800 {
801 c_to_humus_1_sl = 0.0;
802 c_to_humus_2_sl = 0.0;
803 c_to_humus_3_sl = 0.0;
804 humify_humus_1_to_humus_2_sl = 0.0;
805 humify_humus_2_to_humus_3_sl = 0.0;
806 decompose_hum_1 = 0.0;
807 decompose_hum_2 = 0.0;
808 decompose_hum_3 = 0.0;
809
810 if ( _reset_litter)
811 {
812 loose_lit_1 = 0.0;
813 loose_lit_2 = 0.0;
814 loose_lit_3 = 0.0;
815
816 c_to_lit_1 = 0.0;
817 c_to_lit_2 = 0.0;
818 c_to_lit_3 = 0.0;
819
820 loose_aorg = 0.0;
821 c_to_aorg = 0.0;
822 }
823 exit_wood = 0.0;
824 enter_wood = 0.0;
825 }
826
827 inline size_t spinup_type() const
828 {
829 return this->spinup_type_;
830 }
831
832 inline size_t spinup_months() const
833 {
834 return this->spinup_years_ * 12;
835 }
836
837 inline size_t spinup_years() const
838 {
839 return this->spinup_years_;
840 }
841
842 lerr_t stop_spinup()
843 {
844 execute_ = false;
845 return LDNDC_ERR_OK;
846 }
847
848 void set_spinup_type( size_t _t)
849 {
850 this->spinup_type_ = _t;
851 }
852
853 void set_spinup_years( size_t _y)
854 {
855 this->spinup_years_ = _y;
856 if ( this->spinup_years_ > 0)
857 {
858 this->execute_ = true;
859 }
860 }
861
862 size_t simulated_years( cbm::sclock_t const *) const;
863
864 bool spinup_stage( cbm::sclock_t const *) const;
865
866 bool execute_spinup( cbm::sclock_t const *);
867
868 size_t spinup_type_;
869 size_t spinup_years_;
870 size_t executed_months_;
871
872 private:
873
874 bool execute_;
875
876 public:
877
878 lvector< double > c_to_humus_1_sl;
879 lvector< double > c_to_humus_2_sl;
880 lvector< double > c_to_humus_3_sl;
881
882 lvector< double > humify_humus_1_to_humus_2_sl;
883 lvector< double > humify_humus_2_to_humus_3_sl;
884
885 lvector< double > decompose_hum_1;
886 lvector< double > decompose_hum_2;
887 lvector< double > decompose_hum_3;
888
889 lvector< double > loose_lit_1;
890 lvector< double > loose_lit_2;
891 lvector< double > loose_lit_3;
892
893 lvector< double > c_to_lit_1;
894 lvector< double > c_to_lit_2;
895 lvector< double > c_to_lit_3;
896
897 lvector< double > loose_aorg;
898 lvector< double > c_to_aorg;
899
900 lvector< double > c_humus_1_temp_sl;
901 lvector< double > c_humus_2_temp_sl;
902 lvector< double > c_humus_3_temp_sl;
903
904 lvector< double > c_litter_1_temp_sl;
905 lvector< double > c_litter_2_temp_sl;
906 lvector< double > c_litter_3_temp_sl;
907
908 lvector< double > n_litter_1_temp_sl;
909 lvector< double > n_litter_2_temp_sl;
910 lvector< double > n_litter_3_temp_sl;
911
912 lvector< double > c_aorg_temp_sl;
913 lvector< double > n_aorg_temp_sl;
914
915 lvector< double > cn_humus_2_temp_sl;
916 lvector< double > cn_humus_3_temp_sl;
917
918 double exit_wood;
919 double enter_wood;
920 };
921
922 SpinUp spinup_;
923
924
925 /*****************/
926 /*** methods ***/
927 /*****************/
928
934 lerr_t
935 MeTrX_write_output();
936
942 lerr_t
943 MeTrX_write_output_daily();
944
950 lerr_t
951 MeTrX_write_output_yearly();
952
958 lerr_t
959 MeTrX_write_output_layer_daily();
960
966 lerr_t
967 MeTrX_write_output_layer_yearly();
968
974 lerr_t
975 MeTrX_write_output_fluxes();
976
982 lerr_t
983 MeTrX_write_output_pools();
984
990 lerr_t
991 MeTrX_write_output_subdaily();
992
998 lerr_t
999 MeTrX_write_rates();
1000
1006 lerr_t
1007 MeTrX_fertilize();
1008
1009 lerr_t
1010 MeTrX_irrigate();
1011
1017 lerr_t
1018 MeTrX_manure();
1019
1025 lerr_t
1026 MeTrX_till();
1027
1033 lerr_t
1034 MeTrX_reset();
1035
1041 lerr_t
1042 MeTrX_reset_subdaily();
1043
1049 lerr_t
1050 MeTrX_reset_daily();
1051
1057 lerr_t
1058 MeTrX_update();
1059
1065 lerr_t
1066 MeTrX_check_for_negative_value(
1067 char const * /*name*/);
1068
1074 lerr_t
1075 MeTrX_spinup();
1076
1080 lerr_t
1081 MeTrX_balance_check(
1082 unsigned int);
1083
1089 lerr_t
1091
1092 lerr_t
1093 MeTrX_advection();
1094
1100 void
1101 MeTrX_leaching();
1102
1108 void
1109 MeTrX_groundwater_access();
1110
1114 lerr_t
1115 MeTrX_plant_respiration( int /* time step */);
1116
1117 double
1118 MeTrX_get_wfps(
1119 size_t /* soil layer */);
1120
1124 double
1125 MeTrX_get_wfps_eff(
1126 size_t,
1127 double const &);
1128
1134 lerr_t
1135 MeTrX_freeze_thaw();
1136
1142 lerr_t
1143 MeTrX_radon_source_sink();
1144
1148 double
1149 radon_emanation_coeff(
1150 unsigned int,
1151 const double &,
1152 const double &,
1153 const double &,
1154 const double &);
1155
1161 lerr_t
1162 MeTrX_fragmentation();
1163
1167 void
1168 MeTrX_litter_distribution(
1169 double const &,
1170 double const &,
1171 double const &,
1172 double const &,
1173 double const &,
1174 double const &,
1175 lvector< double > &accumulated_litter_sl);
1176
1182 lerr_t
1184
1185 void
1186 MeTrX_liq_diffusion_scale( double &_out, lvector_t< double > &_scale);
1187
1193 void
1195
1201 lerr_t
1202 MeTrX_pertubation();
1203
1209 lerr_t
1210 MeTrX_metabolism();
1211
1217 lerr_t
1219
1220 void
1221 MeTrX_ebullition_transfer(
1222 double &,
1223 double &,
1224 double ,
1225 double );
1226
1232 void
1234
1240 void
1242
1248 void
1250
1256 void
1258
1264 void
1266
1272 void
1274
1280 void
1282
1288 void
1290
1296 lerr_t
1298
1302 double
1303 MeTrX_get_mineral_efficiency(
1304 double,
1305 double);
1306
1310 double
1311 MeTrX_get_micro_c_decay_max(
1312 double &);
1313
1317 double
1318 MeTrX_get_micro_n_decay_max(
1319 double &);
1320
1324 void
1325 MeTrX_dead_microbial_biomass_allocation(
1326 size_t /* soil layer */,
1327 double const & /* carbon transfer amount*/,
1328 double const & /* nitrogen transfer amount*/,
1329 double &,
1330 double &);
1331
1335 void
1336 MeTrX_execute_c_growth(
1337 size_t const &,
1338 double ,
1339 double const &,
1340 double &,
1341 double &);
1342
1346 void
1347 MeTrX_execute_co2_prod(
1348 size_t const &,
1349 double const &,
1350 double &,
1351 double &);
1352
1356 void
1357 MeTrX_execute_n_assimilation(
1358 double const &,
1359 size_t const &,
1360 bool const &,
1361 double &,
1362 double &,
1363 double &);
1364
1368 double
1369 MeTrX_get_n_growth(
1370 double const &,
1371 double const &,
1372 double const &,
1373 double const &,
1374 double const &);
1375
1381 void
1382 MeTrX_urea_hydrolysis();
1383
1389 void
1390 MeTrX_pH_calculation();
1391
1399 lerr_t
1400 MeTrX_nitrogen_fertilizer_release();
1401
1407 void
1409
1415 void
1417
1423 void
1425
1431 void
1432 MeTrX_clay_nh4_equilibrium();
1433
1439 void
1440 MeTrX_nh3_nh4_equilibrium();
1441
1447 void
1449
1453 double
1454 MeTrX_get_ph_sl(
1455 size_t /* soil layer */);
1456
1462 double
1463 MeTrX_get_ph_wl();
1464
1465 double
1466 MeTrX_get_fact_ph_som_turnover( size_t const &);
1467
1473 double
1474 MeTrX_get_fact_tm_decomp( size_t const &);
1475 double
1476 MeTrX_get_fact_clay_decomp( size_t const &);
1477 double
1478 MeTrX_get_fact_clay_humify( size_t const &);
1479 double
1480 MeTrX_get_fact_t_mic( size_t const &);
1481 double
1482 MeTrX_get_fact_m_mic( size_t const &);
1483 double
1484 MeTrX_get_fact_tm_mic( size_t const &);
1485
1486 double
1487 MeTrX_get_fact_t_denit( size_t const &);
1488 double
1489 MeTrX_get_fact_m_denit( size_t const &);
1490 double
1491 MeTrX_get_fact_tm_denit( size_t const &);
1492
1496 inline double MeTrX_get_fact_mm(
1497 double const &_conc,
1498 double const &_k)
1499 {
1500 return (_conc / (_k + _conc));
1501 };
1502
1507 inline double MeTrX_get_k_mm_x_sl(
1508 size_t const &_sl,
1509 double const &_k_mm)
1510 {
1511 return (_k_mm * sc_.h_sl[_sl]);
1512 };
1513
1514
1520 double
1521 MeTrX_get_c_tot();
1522
1528 double
1529 MeTrX_get_n_tot();
1530
1534 double
1535 MeTrX_get_atm_eq_liq(
1536 atm_eq_liq const &,
1537 double const &);
1538
1544 lerr_t
1545 MeTrX_receive_state();
1546
1552 lerr_t
1553 MeTrX_send_state();
1554
1561 lerr_t
1562 MeTrX_dissolution_soil( double const &,
1563 double &,
1564 double &);
1565
1571 lerr_t
1572 MeTrX_update_soil_discretization( bool);
1573
1574 bool
1575 MeTrX_forest_ecosytem();
1576};
1577
1578} /*namespace ldndc*/
1579
1580#endif /* LM_SOILCHEMISTRYMETRX_H_ */
Biogeochemical model MeTrx.
Definition: soilchemistry-metrx.h:29
static const double C_SATURATION
Definition: soilchemistry-metrx.h:34
void MeTrX_soil_organic_matter_turnover()
static const double TNORM
Definition: soilchemistry-metrx.h:31
double MeTrX_get_k_mm_x_sl(size_t const &_sl, double const &_k_mm)
Scales Michaelis-Menten constant according to spatial discretization.
Definition: soilchemistry-metrx.h:1507
Spatially explicit groundwater model.
Definition: airchemistryput.h:15