-
Notifications
You must be signed in to change notification settings - Fork 23
/
SnowMelt.c
executable file
·404 lines (344 loc) · 13.1 KB
/
SnowMelt.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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/*
* SUMMARY: SnowMelt.c - Calculate snow accumulation and melt
* USAGE:
*
* AUTHOR: Mark Wigmosta and Pascal Storck
* ORG: University of Washington, Department of Civil Engineering
* E-MAIL: [email protected]
* ORIG-DATE: 8-Oct-1996 at 08:50:06
* DESCRIPTION: Calculate snow accumulation and melt using an energy balance
* approach for a two layer snow model
* DESCRIP-END.
* FUNCTIONS: SnowMelt()
* COMMENTS:
* $Id: SnowMelt.c,v 1.4 2003/07/01 21:26:25 olivier Exp $
*/
#include <assert.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "brent.h"
#include "constants.h"
#include "settings.h"
#include "massenergy.h"
#include "functions.h"
#include "snow.h"
static float CalcSnowPackEnergyBalance(float Tsurf, ...);
/*****************************************************************************
Function name: SnowMelt()
Purpose : Calculate snow accumulation and melt using an energy balance
approach for a two layer snow model
Required :
int y - Row counter
int x - Column counter
int Dt - Model timestep (seconds)
float Z - Reference height (m)
float Displacement - Displacement height (m)
float Z0 - Surface roughness (m)
float BaseRa - Aerodynamic resistance (uncorrected for
stability) (s/m)
float AirDens - Density of air (kg/m3)
float EactAir - Actual vapor pressure of air (Pa)
float Lv - Latent heat of vaporization (J/kg3)
float ShortRad - Net exchange of shortwave radiation (W/m2)
float LongRadIn - Incoming long wave radiation (W/m2)
float Press - Air pressure (Pa)
float RainFall - Amount of rain (m)
float Snowfall - Amount of snow (m)
float Tair - Air temperature (C)
float Vpd - Vapor pressure deficit (Pa)
float Wind - Wind speed (m/s)
float *PackWater - Liquid water content of snow pack
float *SurfWater - Liquid water content of surface layer
float *Swq - Snow water equivalent at current pixel (m)
float *VaporMassFlux; - Mass flux of water vapor to or from the
intercepted snow (m)
float *TPack - Temperature of snow pack (C)
float *TSurf - Temperature of snow pack surface layer (C)
float *MeltEnergy - Energy used for melting and heating of snow pack
(W/m2)
Returns :
float Outflow - Amount of snowpack outflow (m)
Modifies :
float *PackWater - Liquid water content of snow pack
float *SurfWater - Liquid water content of surface layer
float *Swq - Snow water equivalent at current pixel (m)
float *VaporMassFlux; - Mass flux of water vapor to or from the
intercepted snow (m)
float *TPack - Temperature of snow pack (C)
float *TSurf - Temperature of snow pack surface layer (C)
float *MeltEnergy - Energy used for melting and heating of snow pack
(W/m2)
Comments :
*****************************************************************************/
float SnowMelt(int y, int x, int Dt, float Z, float Displacement, float Z0,
float BaseRa, float AirDens, float EactAir, float Lv,
float ShortRad, float LongRadIn, float Press, float RainFall,
float SnowFall, float Tair, float Vpd, float Wind,
float *PackWater, float *SurfWater, float *Swq,
float *VaporMassFlux, float *TPack, float *TSurf,
float *MeltEnergy)
{
float DeltaPackCC; /* Change in cold content of the pack */
float DeltaPackSwq; /* Change in snow water equivalent of the
pack (m) */
float Ice; /* Ice content of snow pack (m) */
float InitialSwq; /* Initial snow water equivalent (m) */
float MassBalanceError; /* Mass balance error (m) */
float MaxLiquidWater; /* Maximum liquid water content of pack (m) */
float OldTSurf; /* Old snow surface temperature (C) */
float Outflow; /* Amount water flowing out of the snow pack
during the time interval (m) */
float PackCC; /* Cold content of snow pack (J) */
float PackSwq; /* Snow pack snow water equivalent (m) */
float Qnet; /* Net energy exchange at the surface (W/m2) */
float RefreezeEnergy; /* refreeze energy (W/m2) */
float RefrozenWater; /* Amount of refrozen water (m) */
float SnowFallCC; /* Cold content of new snowfall (J) */
float SnowMelt; /* Amount of snow melt during time interval
(m water equivalent) */
float SurfaceCC; /* Cold content of snow pack (J) */
float SurfaceSwq; /* Surface layer snow water equivalent (m) */
InitialSwq = *Swq;
OldTSurf = *TSurf;
/* Initialize snowpack variables */
Ice = *Swq - *PackWater - *SurfWater;
/* Reconstruct snow pack */
if (Ice > MAX_SURFACE_SWE)
SurfaceSwq = MAX_SURFACE_SWE;
else
SurfaceSwq = Ice;
PackSwq = Ice - SurfaceSwq;
/* Calculate cold contents */
SurfaceCC = CH_ICE * SurfaceSwq * *TSurf;
PackCC = CH_ICE * PackSwq * *TPack;
if (Tair > 0.0)
SnowFallCC = 0.0;
else
SnowFallCC = CH_ICE * SnowFall * Tair;
/* Distribute fresh snowfall */
if (SnowFall > (MAX_SURFACE_SWE - SurfaceSwq)) {
DeltaPackSwq = SurfaceSwq + SnowFall - MAX_SURFACE_SWE;
if (DeltaPackSwq > SurfaceSwq)
DeltaPackCC = SurfaceCC + (SnowFall - MAX_SURFACE_SWE) / SnowFall *
SnowFallCC;
else
DeltaPackCC = DeltaPackSwq / SurfaceSwq * SurfaceCC;
SurfaceSwq = MAX_SURFACE_SWE;
SurfaceCC += SnowFallCC - DeltaPackCC;
PackSwq += DeltaPackSwq;
PackCC += DeltaPackCC;
}
else {
SurfaceSwq += SnowFall;
SurfaceCC += SnowFallCC;
}
if (SurfaceSwq > 0.0)
*TSurf = SurfaceCC / (CH_ICE * SurfaceSwq);
else
*TSurf = 0.0;
if (PackSwq > 0.0)
*TPack = PackCC / (CH_ICE * PackSwq);
else
*TPack = 0.0;
/* Adjust ice and *SurfWater */
Ice += SnowFall;
*SurfWater += RainFall;
/* Calculate the surface energy balance for snow_temp = 0.0 */
Qnet = CalcSnowPackEnergyBalance((float) 0.0, Dt, BaseRa, Z, Displacement,
Z0, Wind, ShortRad, LongRadIn, AirDens,
Lv, Tair, Press, Vpd, EactAir, RainFall,
SurfaceSwq, *SurfWater, OldTSurf,
&RefreezeEnergy, VaporMassFlux);
/* If Qnet == 0.0, then set the surface temperature to 0.0 */
if (fequal(Qnet, 0.0)) {
*TSurf = 0.0;
if (RefreezeEnergy >= 0.0) {
RefrozenWater = RefreezeEnergy / (LF * WATER_DENSITY) * Dt;
if (RefrozenWater > *SurfWater) {
RefrozenWater = *SurfWater;
RefreezeEnergy = (RefrozenWater * LF * WATER_DENSITY) / Dt;
}
*MeltEnergy += RefreezeEnergy;
SurfaceSwq += RefrozenWater;
Ice += RefrozenWater;
*SurfWater -= RefrozenWater;
assert(*SurfWater >= 0.0);
SnowMelt = 0.0;
}
else {
/* Calculate snow melt */
SnowMelt = fabs(RefreezeEnergy) / (LF * WATER_DENSITY) * Dt;
*MeltEnergy += RefreezeEnergy;
}
/* Convert vapor mass flux to a depth per timestep and adjust *SurfWater */
*VaporMassFlux *= Dt;
if (*SurfWater < -(*VaporMassFlux)) {
*VaporMassFlux = -(*SurfWater);
*SurfWater = 0.0;
}
else
*SurfWater += *VaporMassFlux;
/* If SnowMelt < Ice, there was incomplete melting of the pack */
if (SnowMelt < Ice) {
if (SnowMelt <= PackSwq) {
*SurfWater += SnowMelt;
PackSwq -= SnowMelt;
Ice -= SnowMelt;
}
else {
*SurfWater += SnowMelt + *PackWater;
*PackWater = 0.0;
PackSwq = 0.0;
Ice -= SnowMelt;
SurfaceSwq = Ice;
}
}
/* Else, SnowMelt > Ice and there was complete melting of the pack */
else {
SnowMelt = Ice;
*SurfWater += Ice;
SurfaceSwq = 0.0;
*TSurf = 0.0;
PackSwq = 0.0;
*TPack = 0.0;
Ice = 0.0;
}
}
/* Else, SnowPackEnergyBalance(T=0.0) <= 0.0 */
else {
/* Calculate surface layer temperature using "Brent method" */
*TSurf = RootBrent(y, x, (float) (*TSurf - DELTAT), (float) 0.0,
SnowPackEnergyBalance, Dt, BaseRa, Z, Displacement,
Z0, Wind, ShortRad, LongRadIn, AirDens, Lv, Tair,
Press, Vpd, EactAir, RainFall, SurfaceSwq, *SurfWater,
OldTSurf, &RefreezeEnergy, VaporMassFlux);
/* since we iterated, the surface layer is below freezing and no snowmelt
*/
SnowMelt = 0.0;
/* Since updated snow_temp < 0.0, all of the liquid water in the surface
layer has been frozen */
SurfaceSwq += *SurfWater;
Ice += *SurfWater;
*SurfWater = 0.0;
*MeltEnergy += (*SurfWater * LF * WATER_DENSITY) / Dt;
/* Convert mass flux to a depth per timestep and adjust SurfaceSwq */
*VaporMassFlux *= Dt;
if (SurfaceSwq < -(*VaporMassFlux)) {
*VaporMassFlux = -SurfaceSwq;
SurfaceSwq = 0.0;
Ice = PackSwq;
}
else {
SurfaceSwq += *VaporMassFlux;
Ice += *VaporMassFlux;
}
}
/* Done with iteration etc, now Update the liquid water content of the
surface layer */
MaxLiquidWater = LIQUID_WATER_CAPACITY * SurfaceSwq;
if (*SurfWater > MaxLiquidWater) {
Outflow = *SurfWater - MaxLiquidWater;
*SurfWater = MaxLiquidWater;
}
else
Outflow = 0.0;
/* Refreeze liquid water in the pack.
variable 'RefreezeEnergy' is the heat released to the snow pack
if all liquid water were refrozen.
if RefreezeEnergy < PackCC then all water IS refrozen
PackCC always <=0.0
WORK IN PROGRESS: This energy is NOT added to MeltEnergy, since this does
not involve energy transported to the pixel. Instead heat from the snow
pack is used to refreeze water */
*PackWater += Outflow; /* add surface layer outflow to pack liquid water */
RefreezeEnergy = *PackWater * LF * WATER_DENSITY;
/* calculate energy released to freeze */
if (PackCC < -RefreezeEnergy) { /* cold content not fully depleted */
PackSwq += *PackWater; /* refreeze all water and update */
Ice += *PackWater;
*PackWater = 0.0;
if (PackSwq > 0.0)
*TPack = (PackCC + RefreezeEnergy) / (CH_ICE * PackSwq);
else
*TPack = 0.0;
}
else {
/* cold content has been either exactly satisfied or exceeded. If
PackCC = refreeze then pack is ripe and all pack water is
refrozen, else if energy released in refreezing exceeds PackCC
then exactly the right amount of water is refrozen to satify PackCC.
The refrozen water is added to PackSwq and Ice */
*TPack = 0.0;
DeltaPackSwq = -PackCC / (LF * WATER_DENSITY);
*PackWater -= DeltaPackSwq;
PackSwq += DeltaPackSwq;
Ice += DeltaPackSwq;
}
/* Update the liquid water content of the pack */
MaxLiquidWater = LIQUID_WATER_CAPACITY * PackSwq;
if (*PackWater > MaxLiquidWater) {
Outflow = *PackWater - MaxLiquidWater;
*PackWater = MaxLiquidWater;
}
else
Outflow = 0.0;
/* Update snow properties */
Ice = PackSwq + SurfaceSwq;
if (Ice > MAX_SURFACE_SWE) {
SurfaceCC = CH_ICE * *TSurf * SurfaceSwq;
PackCC = CH_ICE * *TPack * PackSwq;
if (SurfaceSwq > MAX_SURFACE_SWE) {
PackCC += SurfaceCC * (SurfaceSwq - MAX_SURFACE_SWE) / SurfaceSwq;
SurfaceCC -= SurfaceCC * (SurfaceSwq - MAX_SURFACE_SWE) / SurfaceSwq;
PackSwq += SurfaceSwq - MAX_SURFACE_SWE;
SurfaceSwq -= SurfaceSwq - MAX_SURFACE_SWE;
}
else if (SurfaceSwq < MAX_SURFACE_SWE) {
PackCC -= PackCC * (MAX_SURFACE_SWE - SurfaceSwq) / PackSwq;
SurfaceCC += PackCC * (MAX_SURFACE_SWE - SurfaceSwq) / PackSwq;
PackSwq -= MAX_SURFACE_SWE - SurfaceSwq;
SurfaceSwq += MAX_SURFACE_SWE - SurfaceSwq;
}
*TPack = PackCC / (CH_ICE * PackSwq);
*TSurf = SurfaceCC / (CH_ICE * SurfaceSwq);
}
else {
PackSwq = 0.0;
PackCC = 0.0;
*TPack = 0.0;
}
*Swq = Ice + *PackWater + *SurfWater;
if (fequal(*Swq, 0.0)) {
*TSurf = 0.0;
*TPack = 0.0;
}
/* Mass balance test */
MassBalanceError = (InitialSwq - *Swq) + (RainFall + SnowFall) - Outflow +
*VaporMassFlux;
return (Outflow);
}
/*****************************************************************************
Function name: CalcSnowPackEnergyBalance()
Purpose : Dummy function to make a direct call to
SnowEnergyBalance() possible.
Required :
float TSurf - SnowPack surface temperature (C)
other arguments required by SnowPackEnergyBalance()
Returns :
float Qnet - Net energy exchange at the SnowPack snow surface (W/m^2)
Modifies : none
Comments : function is local to this module
*****************************************************************************/
static float CalcSnowPackEnergyBalance(float Tsurf, ...)
{
va_list ap; /* Used in traversing variable argument list
*/
float Qnet; /* Net energy exchange at the SnowPack snow
surface (W/m^2) */
va_start(ap, Tsurf);
Qnet = SnowPackEnergyBalance(Tsurf, ap);
va_end(ap);
return Qnet;
}