forked from jhamman/DHSVM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SurfaceEnergyBalance.c
executable file
·173 lines (141 loc) · 6.14 KB
/
SurfaceEnergyBalance.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
/*
* SUMMARY: SurfaceEnergyBalance.c - Calculate surface energy balance
* USAGE: Part of DHSVM
*
* AUTHOR: Bart Nijssen
* ORG: University of Washington, Department of Civil Engineering
* E-MAIL: [email protected]
* ORIG-DATE: Apr-1996
* DESCRIPTION: Calculate surface energy balance. This group of functions
* is used by the iterative Brent method to determine the
* surface temperature
* DESCRIP-END.
* FUNCTIONS: SurfaceEnergyBalance()
* COMMENTS:
* $Id: SurfaceEnergyBalance.c,v 1.4 2003/07/01 21:26:26 olivier Exp $
*/
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "settings.h"
#include "massenergy.h"
#include "constants.h"
/*****************************************************************************
Function name: SurfaceEnergyBalance()
Purpose : Calculate the surface energy balance in the absence of snow
Required :
float TSurf - new estimate of effective surface temperature
va_list ap - Argument list initialized by va_start(). For
elements of list and order, see beginning of
routine
Returns :
float RestTerm - Rest term in the energy balance
Modifies : none
Comments :
*****************************************************************************/
float SurfaceEnergyBalance(float TSurf, va_list ap)
{
/* start of list of arguments in variable argument list */
int Dt; /* Model time step (seconds) */
float Ra; /* Aerodynamic resistance (s/m) */
float Z; /* Reference height (m) */
float Displacement; /* Displacement height (m) */
float Z0; /* Surface roughness (m) */
float Wind; /* Wind speed (m/s) */
float ShortRad; /* Net incident shortwave radiation (W/m2) */
float LongRadIn; /* Incoming longwave radiation (W/m2) */
float AirDens; /* Density of air (kg/m3) */
float Lv; /* Latent heat of vaporization (J/kg3) */
float ETot; /* Total evapotranspiration (m) */
float Kt; /* Effective soil thermal conductivity
(W/(m*K)) */
float ChSoil; /* Soil thermal capacity (J/(kg*K)) */
float Porosity; /* Porosity of upper soil layer */
float MoistureContent; /* Moisture content of upper soil layer */
float Depth; /* Depth of soil heat profile (m) */
float Tair; /* Air temperature (C) */
float TSoilUpper; /* Soil temperature in upper layer (C) */
float TSoilLower; /* Soil temperature at Depth (C) */
float OldTSurf; /* Surface temperature during previous time
step */
float MeltEnergy; /* Energy used to melt/refreeze snow pack
(W/m2) */
/* end of list of arguments in variable argument list */
float GroundHeat; /* ground heat exchange at surface (W/m2) */
float HeatCapacity; /* soil heat capacity (J/(m3*C) */
float HeatStorageChange; /* change in ground heat storage (W/m2) */
float LatentHeat; /* latent heat exchange at surface (W/m2) */
float LongRadOut; /* long wave radiation emitted by surface
(W/m2) */
float NetRad; /* net radiation exchange at surface (W/m2) */
float RestTerm; /* rest term in surface energy balance
(W/m2) */
float SensibleHeat; /* sensible heat exchange at surface (W/m2) */
float TMean; /* Mean temperature during interval (C) */
double Tmp; /* temporary variable */
/* Assign the elements of the array to the appropriate variables. The list
is traversed as if the elements are doubles, because:
In the variable-length part of variable-length argument lists, the old
``default argument promotions'' apply: arguments of type float are
always promoted (widened) to type double, and types char and short int
are promoted to int. Therefore, it is never correct to invoke
va_arg(argp, float); instead you should always use va_arg(argp,
double).
(quoted from the comp.lang.c FAQ list)
*/
Dt = va_arg(ap, int);
Ra = (float) va_arg(ap, double);
Z = (float) va_arg(ap, double);
Displacement = (float) va_arg(ap, double);
Z0 = (float) va_arg(ap, double);
Wind = (float) va_arg(ap, double);
ShortRad = (float) va_arg(ap, double);
LongRadIn = (float) va_arg(ap, double);
AirDens = (float) va_arg(ap, double);
Lv = (float) va_arg(ap, double);
ETot = (float) va_arg(ap, double);
Kt = (float) va_arg(ap, double);
ChSoil = (float) va_arg(ap, double);
Porosity = (float) va_arg(ap, double);
MoistureContent = (float) va_arg(ap, double);
Depth = (float) va_arg(ap, double);
Tair = (float) va_arg(ap, double);
TSoilUpper = (float) va_arg(ap, double);
TSoilLower = (float) va_arg(ap, double);
OldTSurf = (float) va_arg(ap, double);
MeltEnergy = (float) va_arg(ap, double);
/* In this routine transport of energy to the surface is considered
positive */
TMean = 0.5 * (OldTSurf + TSurf);
/* Apply the stability correction to the aerodynamic resistance */
if (Wind > 0.0)
Ra /= StabilityCorrection(Z, Displacement, TMean, Tair, Wind, Z0);
else
Ra = DHSVM_HUGE;
/* Calculate the longwave exchange and net radiation, assuming black body */
Tmp = TMean + 273.15;
LongRadOut = STEFAN * (Tmp * Tmp * Tmp * Tmp);
NetRad = ShortRad + LongRadIn - LongRadOut;
/* Calculate the sensible heat flux */
SensibleHeat = AirDens * CP * (Tair - TMean) / Ra;
/* Calculate the latent heat flux */
LatentHeat = -(Lv * ETot) / Dt * WATER_DENSITY;
/* Calculate the ground heat flux */
GroundHeat = Kt * (TSoilLower - TMean) / Depth;
/* Calculate the change in the ground heat storage in the upper
0.1 m of the soil */
HeatCapacity = (1 - Porosity) * ChSoil;
if (TSoilUpper >= 0.0)
HeatCapacity += MoistureContent * CH_WATER;
else
HeatCapacity += MoistureContent * CH_ICE;
HeatStorageChange = (HeatCapacity * (OldTSurf - TMean) * DZ_TOP) / Dt;
/* Calculate the net energy exchange at the surface. The left hand side of
the equation should go to zero for the balance to close, so we want to
minimize the absolute value of the left hand side */
RestTerm =
MeltEnergy + NetRad + SensibleHeat + LatentHeat +
GroundHeat + HeatStorageChange;
return RestTerm;
}