LandscapeDNDC 1.37.0
soilosu.h
1#ifndef M1D_MOD_MICROCLIMATE_SOIL_OSU_H
2#define M1D_MOD_MICROCLIMATE_SOIL_OSU_H
3
4#include "microclimatemodule.h"
5
6
7class MicroClimateOSU : public MicroClimateModule {
8public:
9
11 MicroClimateOSU(ModelCore & modelCore, unsigned int timeInterval) : MicroClimateModule(modelCore,timeInterval),
12 modelCore_(modelCore),
13 time_(modelCore.getLandscape().getTime()),
14 si_(modelCore.getInput().getSite()),
15 sppar_(modelCore.getInput().getParameter().getSpeciesPar()),
16 mc_(const_cast<MicroClimate &>(modelCore.getSubstates().getMc())),
17 sc_(modelCore.getSubstates().getSc()),
18 wc_(modelCore.getSubstates().getWc()),
19 ph_(modelCore.getSubstates().getPh()),
20 vs_(modelCore.getSubstates().getVs())
21 {
22 this->setName("MicroClimateOSU");
23 mois_sl_OSU = new double[slMaxOSU+1]; // soil water content (mm m3)
24 temp_sl_OSU = new double[slMaxOSU+1]; // soil temperature in K
25 h_sl_OSU = new double[slMaxOSU+1]; // heigth of soil layer (mm)
26 poro_sl_OSU = new double[slMaxOSU+1]; // porosity of soil layer pro layer of OSU
27 }
28
29
30 ~MicroClimateOSU(){
31 // delete array variables
32 delete[] mois_sl_OSU;
33 delete[] temp_sl_OSU;
34 delete[] poro_sl_OSU;
35 delete[] h_sl_OSU;
36 }
37
38 void finalize() {
39
40 }
42 void solve() { this->run_( ); }
43
44 private:
45 ModelCore & modelCore_;
46 Timer & time_;
47 Site & si_;
48 SpeciesPar & sppar_;
49 MicroClimate & mc_;
50 SoilChemistry const & sc_;
51 WaterCycle const & wc_;
52 Physiology const & ph_;
53 VegStructure const & vs_;
54
55 //variables
56// int slMaxOSU;
57// double *h_sl_OSU,*poro_sl_OSU,*mois_sl_OSU;
58// double height,lai,dts,etotal;
59// double h_fl1,tempK_fl1,slrad_fl1,vpd_fl1,win_fl1,hum_fl1,
60// slrad,lrad,tempK,tempK_bd,press,vps;
61// int IITERMAX;
62// double KPA_IN_PA,DM3_IN_M3;
63// double SALBF,RD,G,KARMAN,CP,SIGMA,RV,RS;
64// double ST,B,Z0M,HBASE,D_IN_K,DWAT,CWAT,CVSOIL,CVAIR;
65//
66// int co__vtMax;
67// double vs__fDens;
68
69 double *mois_sl_OSU; // soil water content (mm m3)
70 double *temp_sl_OSU; // soil temperature in K
71 double *h_sl_OSU; // heigth of soil layer (mm)
72 double *poro_sl_OSU; // porosity of soil layer pro layer of OSU
73
74 // declaration of module specific parameters
75 static const int IITERMAX; // iteration step for surface temperature
76 static const int slMaxOSU; // number of soil layers considered in OSU
77 static const double HBASE; // soil depth with reference temperature (according to Chen and Dudhia 2001)
78 static const double DTMIN0; // recommended model time step in minutes
79 static const double CVSOIL; // soil volumetric heat capacity [J.m-3.K-1]
80 static const double SALBF; // albedo fraction of bare soil
81 // TODO why static ?
82 // static variables that need to keep their value
83 double mois_sl1;
84 double mois_sl2;
85 double mois_sl3;
86 double mois_sl4;
87 double poro_sl1;
88 double poro_sl2;
89 double poro_sl3;
90 double poro_sl4;
91 double temp_sl1;
92 double temp_sl2;
93 double temp_sl3;
94 double temp_sl4;
95 // variables that need to keep their value
96 double hflux_tsi;
97 double gflux_tsi;
98
99 double ST; // saturated soil water tension [m] (all values according to Chen and Dudhia 2001)
100 double B; // hydraulic conductivity parameter (all values according to Chen and Dudhia 2001)
101 double Z0M; // roughness coefficient [m] (general, species specific or calculated)
102
103 double dthmeteodata; // time step driving meteo data in hours
104 double dtmin; // model time step in minutes
105 double dts; // model time step in seconds
106 double tsread; // calculations per time step
107 double lai; // leaf area of the vegetation
108 double height; // height of the vegetation cover (m)
109 double etotal;
110 double h_fl1,tempK_fl1,slrad_fl1,vpd_fl1,win_fl1,hum_fl1;
111 double slrad,lrad,tempK,tempK_l,tempK_bd,press,vps;
112 double hslcum,hslOSUcum,hslOSUcumOld,hslrest;
113 double hLim,hx,hy,dhsl,fhsl;
114 // Main functions
115
116 /*------------------------------------------------------------------------------
117 Integration of the diffusion equation for soil temperature using the
118 Crank Nicholson scheme
119 ------------------------------------------------------------------------------*/
120
121 void CalcSolvHeat
122 (double &temp_l);
123
124 inline double Max(double x, double y){
125 return (x > y) ? x : y;
126 }
127
128 inline double Min(double x, double y){
129 return (x > y) ? y : x;
130 }
131
132
133 /*----------------------------------------------
134 heat flux equation
135 ----------------------------------------------*/
136
137 // total volumetric heat capacity [J.m-3.K-1]
138 double CalcHeatCap
139 (int sl);
140
141 // thermal conductivity Kt [Wm-1K-1]
142 double CalcTherCond
143 (int sl);
144
145
146 /*----------------------------------------------
147 mathematical function
148 ----------------------------------------------*/
149
150 inline double Sqr(double x){
151 return (x * x);
152 }
153
154 inline double Power(double x,double y){
155 double pow;
156
157 if (x <= 0.0)
158 pow = 0.0;
159 else
160 pow = exp(y*log(x));
161
162 return (pow);
163 }
164
165 inline double Abs(double x){
166 return ( x < 0.0) ? -x : x;
167 }
168
169 inline double Sum(double *array, int iMax){
170 double val = 0.0;
171 for (int i = 1; i <= iMax; i++){
172 val = val + array[i];
173 }
174 return val;
175 }
176
177 void run_();
178
179
180
181};
182
183
184#endif // M1D_MOD_MICROCLIMATE_SOIL_OSU_H
185