forked from jhamman/DHSVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalcAerodynamic.c
executable file
·301 lines (268 loc) · 9.65 KB
/
CalcAerodynamic.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
/*
* SUMMARY: CalcAerodynamic.c - Calculate the aerodynamic resistances
* USAGE: Part of DHSVM
*
* AUTHOR: Bart Nijssen and Pascal Storck
* ORG: University of Washington, Department of Civil Engineering
* E-MAIL: [email protected], [email protected]
* ORIG-DATE: Thu Mar 27 18:00:10 1997
* DESCRIPTION: Calculate the aerodynamic resistances
* DESCRIP-END.
* FUNCTIONS: CalcAerodynamic()
* COMMENTS:
* $Id: CalcAerodynamic.c,v 1.4 2003/07/01 21:26:09 olivier Exp $
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "DHSVMerror.h"
#include "settings.h"
#include "constants.h"
#include "functions.h"
/*****************************************************************************
Function name: CalcAerodynamic()
Purpose : Calculate the aerodynamic resistance for each vegetation
layer, and the wind 2m above the layer boundary. In case of
an overstory, also calculate the wind in the overstory.
The values are normalized based on a reference height wind
speed, Uref, of 1 m/s. To get wind speeds and aerodynamic
resistances for other values of Uref, you need to multiply
the here calculated wind speeds by Uref and divide the
here calculated aerodynamic resistances by Uref
Required :
int NVegLayers - Number of vegetation layers
char OverStory - flag for presence of overstory. Only used if NVegLayers
is equal to 1
float Zref - Reference height for windspeed
float n - Attenuation coefficient for wind in the overstory
float *Height - Height of the vegetation layers (top layer first)
float Trunk - Multiplier for Height[0] that indictaes the top of the
trunk space
float *U - Vector of length 2, with wind for vegetation layers
If OverStory == TRUE the first value is the wind in
the overstory canopy, and the second value the wind
2m above the lower boundary. Otherwise the first
value is the wind 2m above the lower boundary and
the second value is not used.
float *U2mSnow - Wind velocity 2m above the snow surface
float *Ra - Vector of length 2, with aerodynamic resistance values.
If OverStory == TRUE the first value is the aerodynamic
resistance for the the overstory canopy, and the second
value the aerodynamic resistance for the lower boundary.
Otherwise the first value is the aerodynamic resistance
for the lower boundary and the second value is not used.
float *RaSnow - Aerodynamic resistance for the snow surface.
Returns : void
Modifies :
float *U
float *U2mSnow
float *Ra
float *RaSnow
Comments :
*****************************************************************************/
void CalcAerodynamic(int NVegLayers, unsigned char OverStory,
float n, float *Height, float Trunk, float *U,
float *U2mSnow, float *Ra, float *RaSnow)
{
float d_Lower;
float d_Upper;
float K2;
float Uh;
float Ut;
float Uw;
float Z0_Lower;
float Z0_Upper;
float Zt;
float Zw;
K2 = VON_KARMAN * VON_KARMAN;
/* No OverStory, thus maximum one soil layer */
if (OverStory == FALSE) {
if (NVegLayers == 0) {
Z0_Lower = Z0_GROUND;
d_Lower = 0;
}
else {
Z0_Lower = Z0_MULTIPLIER * Height[0];
d_Lower = D0_MULTIPLIER * Height[0];
}
/* No snow */
U[0] = log((2. + Z0_Lower) / Z0_Lower) / log((Zref - d_Lower) / Z0_Lower);
Ra[0] =
log((2. + Z0_Lower) / Z0_Lower) * log((Zref - d_Lower) / Z0_Lower) / K2;
/* Snow */
*U2mSnow = log((2. + Z0_SNOW) / Z0_SNOW) / log(Zref / Z0_SNOW);
*RaSnow = log((2. + Z0_SNOW) / Z0_SNOW) * log(Zref / Z0_SNOW) / K2;
}
/* Overstory present, one or two vegetation layers possible */
else {
Z0_Upper = Z0_MULTIPLIER * Height[0];
d_Upper = D0_MULTIPLIER * Height[0];
if (NVegLayers == 1) {
Z0_Lower = Z0_GROUND;
d_Lower = 0;
}
else {
Z0_Lower = Z0_MULTIPLIER * Height[1];
d_Lower = D0_MULTIPLIER * Height[1];
}
Zw = 1.5 * Height[0] - 0.5 * d_Upper;
Zt = Trunk * Height[0];
if (Zt < (Z0_Lower + d_Lower))
ReportError("Trunk space height below \"center\" of lower boundary", 48);
/* Resistance for overstory */
Ra[0] = log((Zref - d_Upper) / Z0_Upper) / K2 *
(Height[0] / (n * (Zw - d_Upper)) *
(exp(n * (1 - (d_Upper + Z0_Upper) / Height[0])) - 1) + (Zw -
Height[0]) /
(Zw - d_Upper) + log((Zref - d_Upper) / (Zw - d_Upper)));
/* Wind at different levels in the profile */
Uw = log((Zw - d_Upper) / Z0_Upper) / log((Zref - d_Upper) / Z0_Upper);
Uh =
Uw - (1 -
(Height[0] - d_Upper) / (Zw - d_Upper)) / log((Zref -
d_Upper) / Z0_Upper);
U[0] = Uh * exp(n * ((Z0_Upper + d_Upper) / Height[0] - 1.));
Ut = Uh * exp(n * (Zt / Height[0] - 1.));
/* resistance at the lower boundary */
/* No snow */
/* case 1: the wind profile to a height of 2m above the lower boundary is
entirely logarithmic */
if (Zt > (2. + Z0_Lower + d_Lower)) {
U[1] =
Ut * log((2. + Z0_Lower) / Z0_Lower) / log((Zt - d_Lower) / Z0_Lower);
Ra[1] =
log((2. + Z0_Lower) / Z0_Lower) * log((Zt -
d_Lower) / Z0_Lower) / (K2 * Ut);
}
/* case 2: the wind profile to a height of 2m above the lower boundary
is part logarithmic and part exponential, but the top of the overstory
is more than 2 m above the lower boundary */
else if (Height[0] > (2. + Z0_Lower + d_Lower)) {
U[1] = Uh * exp(n * ((2. + Z0_Lower + d_Lower) / Height[0] - 1.));
Ra[1] =
log((Zt - d_Lower) / Z0_Lower) * log((Zt -
d_Lower) / Z0_Lower) / (K2 *
Ut) +
Height[0] * log((Zref - d_Upper) / Z0_Upper) / (n * K2 *
(Zw -
d_Upper)) * (exp(n *
(1 -
Zt
/
Height
[0]))
-
exp(n *
(1 -
(Z0_Lower
+
d_Lower
+
2.)
/
Height
[0])));
}
/* case 3: the top of the overstory is less than 2 m above the lower
boundary. The wind profile above the lower boundary is part logarithmic
and part exponential, but only extends to the top of the overstory */
else {
U[1] = Uh;
Ra[1] =
log((Zt - d_Lower) / Z0_Lower) * log((Zt -
d_Lower) / Z0_Lower) / (K2 *
Ut) +
Height[0] * log((Zref - d_Upper) / Z0_Upper) / (n * K2 *
(Zw -
d_Upper)) * (exp(n *
(1 -
Zt
/
Height
[0]))
- 1);
fprintf(stderr,
"WARNING: Top of overstory is less than 2 meters above the lower boundary\n");
}
/* Snow */
/* case 1: the wind profile to a height of 2m above the lower boundary is
entirely logarithmic */
if (Zt > (2. + Z0_SNOW)) {
*U2mSnow = Ut * log((2. + Z0_SNOW) / Z0_SNOW) / log(Zt / Z0_SNOW);
*RaSnow = log((2. + Z0_SNOW) / Z0_SNOW) * log(Zt / Z0_SNOW) / (K2 * Ut);
}
/* case 2: the wind profile to a height of 2m above the lower boundary
is part logarithmic and part exponential, but the top of the overstory
is more than 2 m above the lower boundary */
else if (Height[0] > (2. + Z0_SNOW)) {
*U2mSnow = Uh * exp(n * ((2. + Z0_SNOW) / Height[0] - 1.));
*RaSnow = log(Zt / Z0_SNOW) * log(Zt / Z0_SNOW) /
(K2 * Ut) +
Height[0] * log((Zref - d_Upper) / Z0_Upper) / (n * K2 *
(Zw -
d_Upper)) * (exp(n *
(1 -
Zt
/
Height
[0]))
-
exp(n *
(1 -
(Z0_SNOW
+
2.)
/
Height
[0])));
}
/* case 3: the top of the overstory is less than 2 m above the lower boundary.
The wind profile above the lower boundary is part logarithmic and part
exponential, but only extends to the top of the overstory */
else {
*U2mSnow = Uh;
*RaSnow = log(Zt / Z0_SNOW) * log(Zt / Z0_SNOW) /
(K2 * Ut) +
Height[0] * log((Zref - d_Upper) / Z0_Upper) / (n * K2 *
(Zw -
d_Upper)) * (exp(n *
(1 -
Zt
/
Height
[0]))
- 1);
fprintf(stderr,
"WARNING: Top of overstory is less than 2 meters above the lower boundary\n");
}
}
}
/*****************************************************************************
The following is a small main program that helps in testing the function
CalcAerodynamic().
To compile you also need the files ReportError.c and InitErrorMessage.c, and
the appropriate header files.
To compile the test program (using gcc):
gcc -DTEST_MAIN -o test_aero ReportError.c InitErrorMessage.c CalcAerodynamic.c -lm
then run the program by typing test_aero.
*****************************************************************************/
#ifdef TEST_MAIN
int main(void)
{
float Ra[2] = { 0, 0 };
int NVegLayers = 1;
char OverStory = FALSE;
float Zref = 80;
float n = .5;
float Height[2] = { .3, .2 };
float Trunk = 0.3;
float RaSnow;
float UoverStory = 0.0;
float U[2] = { 0, 0 };
float U2mSnow = 0.0;
InitErrorMessage();
CalcAerodynamic(NVegLayers, OverStory, Zref, n, Height, Trunk, U, &U2mSnow,
Ra, &RaSnow);
return EXIT_SUCCESS;
}
#endif