LandscapeDNDC 1.37.0
soilchemistry-dndc.h
1
16#ifndef LM_SOILCHEMISTRY_DNDC_H_
17#define LM_SOILCHEMISTRY_DNDC_H_
18
19#include "mbe_legacymodel.h"
20#include "state/mbe_state.h"
21#include "ld_shared.h"
22#include "ld_isotopes.h"
23#include "soilchemistry/dndc/output-soilchemistry-dndc.h"
24
25#include "soilchemistry/ld_enhanced_efficiency_nitrogen_fertilizers.h"
26
27#include "eventhandler/fertilize/fertilize.h"
28#include "eventhandler/till/till.h"
29
30#include <input/event/events.h>
31
32class solver_tridiagonal_t;
33
34namespace ldndc {
35class LDNDC_API SoilChemistryDNDC : public MBE_LegacyModel
36{
37 /*** module specific constants ***/
38
40 static const unsigned int IMAX_S;
41
43 static const unsigned int NN;
44
46 static const double TNORM;
47
49 static const double HLIM;
50
52 static const double FRN2;
53
54 LMOD_EXPORT_MODULE_INFO(SoilChemistryDNDC,"soilchemistry:dndc","Soilchemistry DNDC");
55 public:
56 SoilChemistryDNDC(
57 MoBiLE_State *,
58 cbm::io_kcomm_t *,
59 timemode_e);
60
61 ~SoilChemistryDNDC();
62
63 lerr_t configure( ldndc::config_file_t const *);
64 lerr_t initialize();
65
66 lerr_t register_ports( cbm::io_kcomm_t *);
67 lerr_t unregister_ports( cbm::io_kcomm_t *);
68
69 lerr_t solve();
70 lerr_t finalize();
71
72 lerr_t sleep() { return LDNDC_ERR_OK; }
73 lerr_t wake() { return LDNDC_ERR_OK; }
74
75 private:
76 cbm::io_kcomm_t * io_kcomm;
77
78 input_class_groundwater_t const * gw_;
79 input_class_siteparameters_t const & sipar_;
80 input_class_soillayers_t const & sl_;
81
82 substate_surfacebulk_t & sb_;
83 substate_airchemistry_t const & ac_;
84 substate_microclimate_t const & mc_;
85 substate_physiology_t const & ph_;
86 substate_soilchemistry_t & sc_;
87 substate_watercycle_t & wc_;
88
89 MoBiLE_PlantVegetation * m_veg;
90
91 timemode_e const timemode_;
92
93 OutputSoilchemistryDNDC output_writer;
94 ldndc_flt64_t * output_buffer;
95
96 EventHandlerFertilize m_eventfertilize;
97 EventHandlerTill m_eventtill;
98
99 CBM_Handle m_PlantHandle;
100 int m_PlantCounter;
101
102 private:
103
104 double * d_soil_eff_;
105
106 solver_tridiagonal_t * tdma_solver_;
107
108 double *waterflux_sl;
109 double *accumulated_waterflux_old_sl;
110
111 lvector_t< double > crb_l; // very labile active organic carbon
112 lvector_t< double > crb_r; // labile active organic carbon
113 lvector_t< double > hdc_l; // recalcitrant active organic carbon
114 lvector_t< double > hdc_r; // very recalcitrant active organic carbon
115
116 lvector_t< double > p_o2_sl;
117 lvector_t< double > fdeni;
118 lvector_t< double > day_co2;
119 lvector_t< double > co2_auto_sl;
120 lvector_t< double > anvf_old;
121 lvector_t< double > nitrify_n2o;
122
123 lvector_t< double > communicate_sl;
124
125 lvector_t< double > factorA;
126 lvector_t< double > factorB;
127 lvector_t< double > flux_chem_no_sl;
128 lvector_t< double > flux_chem_n2o_sl;
129
130 double no_0;
131 double n2o_0;
132 double an_no_0;
133 double an_n2o_0;
134
135 double day_floor_no;
136 double day_floor_n2o;
137 double day_floor_an_no;
138 double day_floor_an_n2o;
139
140 double day_no3_groundwater_access;
141 double year_no3_groundwater_access;
142
143 double n2o_atm;
144 double no_atm;
145
146 double day_mineral_litter;
147 double day_mineral_humus;
148 double day_mineral_microbes;
149 double day_mineral_aorg;
150 double day_mineral_humads;
151
152 lerr_t SCDNDC_step_initialize_();
153 lerr_t SCDNDC_step_finalize_();
154
155
156
157
161 lerr_t
162 SCDNDC_write_output();
163 lerr_t
164 SCDNDC_write_output_daily();
165
166
168 void SCDNDC_urea_hydrolysis();
169
171 void SCDNDC_autotrophic_respiration();
172
174 void SCDNDC_littering();
175
177 void SCDNDC_pertubation();
178
193 void SCDNDC_distribute_among_litter_layers(
194 double _add_c[],
195 double _n_diff);
196
198 void SCDNDC_nh4_clay_equilibrium();
199
201 void SCDNDC_calc_sl_arrays();
202
204 void SCDNDC_split_aorg();
205
207 void SCDNDC_combine_aorg();
208
210 void SCDNDC_litter_decomposition();
211
213 void SCDNDC_humus_decomposition();
214
216 void SCDNDC_microbial_dynamics();
217
219 void SCDNDC_humads_decomposition();
220
222 void SCDNDC_nh4_nh3_dynamics();
223
225 void SCDNDC_nitrification();
226
228 void SCDNDC_denitrification();
229
231 void SCDNDC_gas_diffusion();
232
234 void SCDNDC_groundwater_access();
235
237 void SCDNDC_leaching();
238
240 void SCDNDC_o2_diffusion();
241
243 void SCDNDC_anvf();
244
246 double SCDNDC_temp_mois(
247 size_t);
248
250 void SCDNDC_decomp_litter(
251 size_t sl,
252 double rcn,
253 double decoConstant,
254 double microUse,
255 double temp_mois_fact,
256 double &crb_l,
257 double &rc);
258
260 void SCDNDC_wood_decomposition();
261
263 void SCDNDC_nh4_nh3_equilibrium();
264
266 void SCDNDC_nh3_volatilization();
267
269 void SCDNDC_diffusion(
270 size_t,
271 double,
272 double,
273 double &,
274 double &);
275
277 void SCDNDC_conversion(
278 size_t sl,
279 double CNEFF,
280 double MWN,
281 double n_sum,
282 double doc_MM,
283 double fn,
284 double MAINTENANCE,
285 double MAXRGR,
286 double MAXYLD,
287 double phk,
288 double f_MM,
289 double &deniC,
290 lvector_t< double > & an_doc,
291 lvector_t< double > & day_co2,
292 double &chem_from,
293 double &chem_to);
294
296 void SCDNDC_chemodenitrification(
297 size_t sl,
298 double fts);
299
301 void SCDNDC_emission();
302
303 double SCDNDC_get_fact_o2(size_t /* soil layer */);
304
305 double SCDNDC_get_wfps(
306 size_t /* soil layer */);
307
308 /* balance check switch */
309 bool bc_warn;
310 double bc_tolerance;
311
312 lerr_t SCDNDC_balance_check(
313 unsigned int /*stage*/, double * /*carbon*/, double * /*nitrogen*/);
314 double SCDNDC_get_c_tot();
315 double SCDNDC_get_n_tot();
316
317 Isotopes isotope;
318};
319
320} /*namespace ldndc*/
321
322#endif /* LM_SOILCHEMISTRY_DNDC_H_ */
323
Spatially explicit groundwater model.
Definition: airchemistryput.h:15