-
Notifications
You must be signed in to change notification settings - Fork 11
/
gpusnowdgtv.cpp
1768 lines (1639 loc) · 79.8 KB
/
gpusnowdgtv.cpp
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//copied from snowdgtv.f90
//_# 6.6.13
# include "gpuuebpgdecls.h"
//**********************************************************************************************
//
// Copyright (C) 2012 David Tarboton, Utah State University, [email protected]. http://hydrology.usu.edu/dtarb
//
// This file is part of UEB.
//
// UEB is open source software: you can redistribute it and/or modify it under the terms of the
// MIT Open Source License as published by the Open Source Initiative https://opensource.org/licenses/MIT.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// If you wish to use or incorporate this program (or parts of it) into
// other software that does not meet the MIT Open Source License
// conditions contact the author to request permission.
// David G. Tarboton
// Utah State University
// 8200 Old Main Hill
// Logan, UT 84322-8200
// USA
// http://hydrology.edu/dtarb/
// email: [email protected]
//
//**********************************************************************************************
// Definitions
// dt time step in hours
// nt number of time steps
// input -- input forcing
// input(1,*) air temperature (C)
// input(2,*) precipitation (m/hr)
// input(3,*) wind speed (m/s)
// input(4,*) relative humidity (on a 0-1 scale)
// input(5,*) incoming short wave (kJ/m^2/h)
// input(6,*) net radiation (kJ/m^2/h)
// input(7,*) Cosine of Zenith angle
// SITEV -- site variables
// site variables (1-5)
// sitev(1) drift factor (No detailed information give 1)
// sitev(2) air pressure (Pa)
// sitev(3) ground heat flux Kj/m^2/hr (3.6 = 1 W/m^2)
// sitev(4) albedo extinction parameter (m)
// STATEV
// statev(1) Snow Energy Content (KJ/m^2)
// statev(2) Snow Water Equivalent (m) relative to T = 0 C solid phase
// statev(4) Canopy Snow Water Equivalent (m) relative to T = 0 C solid phase
// statev(3) Dimensionless age of snow surface (or albedo - depending on flag 4)
// statev(5) Refreezing depth (m) used as refdepth
// statev(6) Refreezing depth (m) used as totalrefdepth
// totalrefdepth is a misnomer. These are the same quantity - the refreezing depth. They are repeated because
// when refdepth exceeds the diurnal penetration depth it is set to 0 to tell the code to use the regular
// surface temperature functions while totalrefdepth is only reset to 0 when there is actual melt generated
// or energy content becomes negative indicating freezing of all liquid phase. This ensures that the regular
// surface temperature functions persist when there is liquid water present but the refreezing front has penetrated
// to depth greater than diurnal temperature fluctuations.
// TsPrevday(1:nstepday) Surface temperature over the last 24 hours
// TavePrevday(1:nstepday) Depth average te
// Imperature over the last 24 hours
//
// PARAM -- snowmelt model parameters (see below)
// iflag -- flags
// iflag(1) 0=radiation is shortwave in col 5 and longwave in col 6, else = net radiation in column 7
// iflag(2) no 0 (/yes 1) printing
// iflag(3) unit to which to print
// iflag(4) how albedo calculations are done (a value 1 means albedo is calculated, otherwise statev(3) is albedo
// iflag(5) model option for surface temperature approximation
// 1) the Simple Gradient, almost the same as Original UEB,
// 2) Simple Gradient approach with shallow snow correction.
// 3) The classical force-restore approach.
// 4) Modified force-restore approach.
// cump,cume,cummr -- cumulative precipitation (with df), cumulative evaporation, cumulative melt over time step in m
// outv -- output variables
// outv(1)=prain rain m/hr
// outv(2)=ps snow m/hr
// outv(3)=a albedo
// outv(4)=qh sensible heat (kJ/m2/hr)
// outv(5)=qe latent heat (kJ/m2/hr)
// outv(6)=e sublimation m/hr
// outv(7)=mr melt outflow m/hr
// outv(8)=qm heat advected with melt
// outv(9)=q Energy rate of change (kJ/m2/hr)
// outv(10)=fm Mass rate of change (m/hr)
// outv(11)=tave Average temperature (C)
// outv(12)=tsurf Surface temperature C
// outv(13)=qnet Net Radiation (kJ/m2/hr)
// outv(14)=smelt Surface melt m/hr
//
//yjs Note: in this subroutine, the outv is an array which passes value to this subroutine and back to the snow
//yjs drive program. The Outv(9) and outv(10) pass the daily average snowpack temperature and daily
//yjs snow surface temperature to this subroutine but pass the Qin total and combined mass fluxes
//yjs back. //
__host__ __device__ void uebCell::SNOWUEB2()
{
int iradfl;
//FILE *outUnit;
//CHANGES TO ACCOMODATE GLACIER
float WGT; // WGT=WATER EQUIVALENT GLACIER THICKNESS
int iTsMethod; //yjs Add model time initialization 09/19/2000
float SWIT,SWISM, SWIR,SWIGM;
//definition added--didn't exit in the forrtran version 5.6.13
float refDepth, totalRefDepth, Us_old;
float RRHOI, RRHO ,RID;
float Ta, P, V, RH, Qsi, Qli, Qnetob, cosZen, Tave;
//int snowdgtvariteflag = 0;
float Ps, Pr, Alb/*previously A*/, Rhofs, S;
//outputs from Predictor corrector
float Tc, QHc, QEc, Ec, Qpc, Qmc, Mc, FMc, intc, Inmax, ieff, Ur, Taufb, Taufd, Qsib, Qsid, Taub, Taud, Qsnc, Qsns, Qlnc, Qlns, Rkinc, Rkinsc, Vz, Tac;
// Just for testing (outputs from predictor corre)
float QHs, QEs, Es, QPs, Mr, QMs, Q, FM, TSURFs, Tavepc, Qnet, smelt, Qlis;
// Parameters
float Tr = Param[0], // Temperature above which all is rain [3 C],
Ts = Param[1], // Temperature below which all is snow [-1 C],
Ems = Param[2], // emmissivity of snow [nominally 0.99],
cg = Param[3], // Ground heat capacity [nominally 2.09 KJ/kg/C],
rho = Param[6], // Snow Density [Nominally 450 kg/m^3],
rhog = Param[7], // Soil Density [nominally 1700 kg/m^3],
lc = Param[8], // Liquid holding capacity of snow [0.05],
de = Param[10], // Thermally active depth of soil [0.1 m],
abg = Param[11], // Bare ground albedo [0.25],
avo = Param[12], // Visual new snow albedo [0.95],
anir0 = Param[13], // NIR new snow albedo [0.65],
dNewS = Param[20], // The threshold depth of for new snow [0.001 m],
gsurf = Param[21], // The fraction of surface melt that runs off [e.g. from a glacier],
// 7 Parameters added for canopy
EmC = Param[22]; // Emissivity of canopy
// Some initializations
Rkinc=0.0;
Tac=0.0;
// State Variables - These serve as initial conditions
float Us = statev[0], // Snow Energy Content [KJ/m^2];
Ws = statev[1], // Snow Water Equivalent [m]; relative to T = 0 C solid phase
Wc = statev[3]; // Added for canopy
/*if(snowdgtvariteflag == 1)
for (int ki=0;ki<4; ki++)
cout<<statev[ki]<<endl;
cout<<Ws<<" "<<Wc<<endl;
*/
if(Us <= 0.0)
{
refDepth = 0.0;
totalRefDepth = 0.0;
}
else
{
refDepth = statev[4];
totalRefDepth = statev[5];
}
// Save Old Value 07/23/01
Us_old = Us;
// Site Variables
float dF = sitev[0], // Drift factor
Aep = sitev[3], // Albedo extinction parameter to smooth
// transition of albedo when snow is shallow. Depends on Veg. height [m],
// 7 Site Variables added for canopy
Cc = sitev[4], // Canopy Coverage
LAI = sitev[6], // Leaf Area Index
Sbar = sitev[7]; // Maximum snow load held per unit branch area[Kg/m2 for Pine],
// Control flags
iradfl= iflag[0];
//ounit = iflag[2]; //iflag(4) albedo caculation
iTsMethod = iflag[4]; // the method to approximate the surface temperature
// 1 normal old snow melt model
// 2 revised direct gradient method (New method for ke) and qe
// 3 force restore approach
// 4 modified force restore approach
// Different densities and their ratio
RRHOI= Rho_i/Rho_w;
RRHO = rho/Rho_w;
RID = 1.0/RRHO-1.0/RRHOI; //used to compute melt water flux (Fmelt)
// for Gracier melting calculation
if((sitev[9] == 0) || (sitev[9] == 3))
WGT=0.0;
else
WGT=1.0;
Ws = Ws+WGT;
// loop over nt removed here because UEBGrid makes single call to this function
//#_5.6.13
// DO 2 i = 1,nt
// Input variables
Ta =Inpt[0]; // Air temperature Inpt [Degrees C];
P =Inpt[1]; // Precipitation rate Inpt [m/hr];
V =Inpt[2]; // Wind Speed [m/s];
RH =Inpt[3]; // Relative humidity [fraction 0-1];
// if[iradfl.eq.0];THEN // Inpt is incoming short and longwave
Qsi=Inpt[4]; // Incoming shortwave radiation [KJ/m^2/hr];
Qli=Inpt[5]; // Incoming longwave radiation [KJ/m^2/hr];
// ELSE
Qnetob = Inpt[6]; // Net allwave radiation [KJ/m^2/hr];
// ENDIF
cosZen = Inpt[7]; // Cos[angle between direct sunlight and surface normal];
// Representative value over time step used in albedo calculation.
// We neglect the difference between direct and diffuse albedo.
//DGT Daily average temperatures handled internally so that multiple time steps will work
Tssk_ave = daily_ave(tsprevday, nstepinaDay, -100.0) + T_k; // (K) Surface temperature average over last 24 hours
Tsavek_ave = daily_ave(taveprevday, nstepinaDay, -100.0) + T_k; // (K) Depth averaged temperature average over last 24 hours
// if(snowdgtvariteflag == 1)
//cout<<Tssk_ave<<" "<<Tsavek_ave<<endl;
Tssk_old = tsprevday[nstepinaDay-1] + T_k; // (C) Surface temperature from previous time step
Tsavek_old = taveprevday[nstepinaDay-1] + T_k; // (C) Average temperature from previous time step
// ifany of these variables are out of range due to any problem set them back to freezing
if(Tssk_old < 0)
{
if(snowdgtvariteflag == 1)
cout<<"Invalid previous time step surface temperature set to 273 K"<<Tssk_old<<endl;
Tssk_old = T_k;
}
if(Tsavek_old < 0)
{
if(snowdgtvariteflag == 1)
cout<<"Invalid previous time step average temperature set to 273 K"<<Tsavek_old<<endl;
Tsavek_old = T_k;
}
if(Tssk_ave < 0)
{
if(snowdgtvariteflag == 1)
cout<<"Invalid last 24 hr average surface temperature set to 273 K"<<Tssk_ave<<endl;
Tssk_ave = T_k;
}
if(Tsavek_ave < 0)
{
if(snowdgtvariteflag == 1)
cout<<"Invalid last 24 hr average temperature set to 273 K"<<Tsavek_ave<<endl;
Tsavek_ave = T_k;
}
// Separate rain and snow
Ps = PARTSNOW(P,Ta,Tr,Ts);
Pr = P - Ps;
// Increase precipitation as snow by drift multiplication factor
Ps = Ps * dF;
// Calculate Albedo
// for Gracier melting calculation
if(iflag[3] == 1)
// if(SITEV(10) .EQ. 0 .OR. SITEV(10) .EQ. 3)THEN
Alb = ALBEDO(statev[2], cosZen, (Ws-WGT)/RRHO, Aep, abg, avo, anir0); // Snow depth (Ws/RRho)
// ELSE // Use of this albedo throughout time step neglects the
// A=albedo(statev(3),cosZen,(Ws-WGT)/RRHO,aep,abg,avo,anir0)// changes due to new snow within a time step.o
// ENDIF
else
Alb = statev[2];
//************ Maximum Interception, Literature ************************
// This model assumes that rainfall interception and thoroughfall occurs in a similar way that snowfall interception and unloading does.
// However this model is not suitable to model the rainfall interception and throughfall
Rhofs = 67.92 + 51.25 * expf(Ta/2.59); // Density of fresh snow from air temp, Army Corps 1956.
S = Sbar * (0.27 + 46/Rhofs ); // canopy holding capacity depends on density of snow (Headstrom and Pomeroy (1998))
Inmax = S * LAI; // kg/m2 =lit/m2 = .001m3/m2=.001 m =1/1000 m ()
if(Cc > 0)
Inmax = Inmax/1000 * Cc; // convert to m for per sq m of canopy
else
Inmax = 0;
//if(snowdgtvariteflag == 1)
//cout<<LAI<<" "<<Cc<<" "<<" "<<Sbar<<" "<<Rhofs<<" "<<S<<" "<<Inmax<<endl;
// Call predictor corrector subroutine to do all the work for Canopy
PREDICORRc(Us,Ws,Wc,Alb,fModeldt,RID,P,Pr,Ps,Ta,V,RH,Qsi,Qli,atff, cosZen,EmC,Ems,Param,sitev,iradfl,Qnetob,iTsMethod,mtime,
Tc,QHc,QEc,Ec,Qpc,Qmc,Mc,FMc,intc,Inmax,ieff,Ur, cf,Taufb,Taufd,Qsib,Qsid,Taub,Taud,Qsnc,Qsns,Qlnc,Qlns,Rkinc,
Rkinsc,Vz,Tac, QHs, QEs, Es, QPs, Mr, QMs, Q, FM, TSURFs, Tavepc, Qnet, refDepth, totalRefDepth, smelt, gsurf,Qlis);
// DGT 4/2/05 Despite all checks in predicor It can (and does) occur that we still have Us so large that it results in tavepc greater than 0, which implies that all the
// snow is liquid. In these cases - just force the snow to disappear and add the energy involved to Qm.
Tave = TAVG(Us,Ws,Rho_w,C_s,T_0,rhog,de,cg,H_f); // this call necessary to keep track of average internal temperature used in some surface energy algorithms.
if(snowdgtvariteflag == 1)
cout<<Tave<<endl;
if(Tave > 0) // all is liquid so snow must disappear
{
Mr = Mr+Ws/fModeldt;
QMs = QMs+Ws/fModeldt*Rho_w*H_f;
Q = Q-Ws/fModeldt*Rho_w*H_f;
Us = Us-Ws/fModeldt*Rho_w*H_f;
Ws = 0.0;
}
// since Us, Ws was changed need T_0 re-evaluate Tave
Tave = TAVG(Us,Ws,Rho_w,C_s,T_0,rhog,de,cg,H_f);
//if(snowdgtvariteflag == 1)cout<<Tave<<endl;
// DGT 7/25/05 T_0 guard against unreasonable Us when there is no snow do not allow bulk temperature T_0 go above 10 C
if(Tave > 10)
{
Us=rhog*de*cg*10.0;
Tave = 10.0;
}
// Update snow surface age based on snowfall in time step
if(iflag[3] ==1)
AGESN(statev[2],fModeldt,Ps,TSURFs,T_k,dNewS);
// if(snowdgtvariteflag == 1)
//cout<<statev[2]<<endl;
// 2013 - Introduced glacier substrate into model
// Partition melt outflow into the portion that is from rain, snow and glacier
// Inputs are condensation (C=max(-Es,0)), precipitation as rain (pr) and precipitation as snow (Ps)
// Outputs are melt (Mr) and sublimation (Sub=Max(Es,0))
// DW is change in snow water equivalent (positive if decrease)
// DG is change in glacier (positive if decrease)
// Mass balance
// DW+DG=Mr+Sub-Pr-Ps-C
// In the case of snow left on the ground/glacier - any rain is assumed to have added to the snow
float SnowLeft = findMax(Ws-WGT,0.0);
float DW = (statev[1] - SnowLeft)/fModeldt; // change in seasonal snow rate
// Reduction in snow storage is snow at the beginning minus the snow at the end in excess of glacier. Can be negative if snow increases
float DG = findMax(WGT-Ws,0.0)/fModeldt; // Reduction in glacier storage rate
float R, MSX, MRX, Ms, MG, Eglacier;
if(SnowLeft > 0.)
{
R=0.0; // No outflow due to rain
// Inequalities that hold
// 0<= Ms <= Ps+Pr+C+DW
// 0<= MG <= DG
// The slack in these inequalities is due to Sub
// Compute Ms and MG using proportioning
MSX = Ps+Pr+DW+ findMax(-Es,0.0); // Maximum melt contrib from snow. Note that condensation is taken to add to snow as is rain
MRX = MSX+DG; // Maximum melt overall
// Mr is less than MRX due to sublimation losses. Do the rain proportioning accordingly
if(MRX <= 0.0)
{
Ms=0.0;
MG=0.0;
}
else
{
Ms=Mr*MSX/MRX;
MG=Mr*DG/MRX;
}
}
else
{// The case where all seasonal snow is gone and precipitation may contribute to total outflow
// Inequalities that hold
// 0<= Ms <= Ps+C+DW
// 0<= R <= Pr
// 0<= MG <= DG
// The slack in these inequalities is due to Sub. Note that here Pr may contribute to R but that C is still put to snow
MSX = Ps+DW+ findMax(-Es,0.0); // Maximum melt contrib from snow. Note that condensation is taken to add to snow as is rain
MRX = MSX+DG+Pr; // Maximum melt overall
if(MRX <= 0.0)
{
Ms=0.0;
R=0.0;
MG=0.0;
}
else
{
Ms=Mr*MSX/MRX;
R=Mr*Pr/MRX;
MG=Mr*DG/MRX;
}
}
Eglacier=DG-MG;
SWISM=Ms;
SWIGM=MG;
SWIR=R;
SWIT=Mr;
if(Ws < WGT) // There was glacier melt
Ws=0.0; // Reset
else // Here ws is greater than the glacier thickness so no glacier melt
Ws=Ws-WGT;
/* commented out 10.2.13 relacing with the above
// Partition of melt outflow between rain and snow melt for non glacier case
if(Ws > 0)
{
SWIR = 0;
SWISM = Mr;
}
else // This else case is never entered for glaciers because the entire WGT is not melted in one time step
{
AvailableSnow = (Ps + statev[1]/fModeldt);
SWISM = findMin(AvailableSnow,Mr); // This bounds snow surface melt by the available snow - the balance is due T_0 rain
SWIR = Mr-SWISM;
}
// Correction T_0 partition T_0 account for presence of glaciers
if(Ws < WGT) // There was glacier melt
{
AvailableSnow = (Ps+statev[1]/fModeldt);
SWISM = findMin(AvailableSnow,Mr); // This bounds snow surface melt by the available snow - the balance is due T_0 rain
RemainingAvailableWater = Mr-SWISM; // This is the remaining melt T_0 allocate
SWIGM = findMin(RemainingAvailableWater,(WGT-Ws)/fModeldt);
SWIR = Mr-SWISM-SWIGM;
Ws = 0; // Reset
}
else // Here ws is greater than the glacier thickness so no glacier melt
{
Ws = Ws - WGT;
SWIGM = 0;
}
// SWIT=Mr+SWIGM // DGT 2/22/13. THis seems wrong
SWIT = Mr; // The total is always Mr */
// accumulate for mass balance
cumP = cumP+(Ps+Pr)*fModeldt;
cumEs = cumEs+Es*fModeldt;
cumEc = cumEc+Ec*fModeldt; // Evaporation from canopy
cumMr = cumMr+Mr*fModeldt; // canopy melt not added
cumGm = cumGm+SWIGM*fModeldt; // Cumulative glacier melt
cumEg= cumEg+Eglacier*fModeldt;
// yjs update the total depth of the refreezing depth in the snow pack according the the refreezing depth at time step and the positive energy Inpt. 07/22/01
// DGT's revised logic 1/13/05
if(lc > 0 )
{
if(refDepth > 0)
totalRefDepth = refDepth; // ifrefreezing depth increases totalRefDepth keeps track
else
{ // here refDepth has gone T_0 0 somehow
if( (Mr > 0) || (Us > Us_old && Us > 0)) // ifthere is melt or an increase in energy refDepth is reset
totalRefDepth = 0.0;
}
}
else if ( (Mr > 0) || (Us > Us_old && Us > 0)) // Here lc=0. ifthere is melt or an increase in energy refDepth is reset
totalRefDepth =0.0; // This is likely redundant because iflc=0 then there is no meltwater T_0 refreeze
if(totalRefDepth < 0)
totalRefDepth = 0.0;
//yjs update tsbackup and tavebackup
for(int ii = 0; ii< nstepinaDay-1; ++ii)
{
tsprevday[ii] = tsprevday[ii+1];
taveprevday[ii]= taveprevday[ii+1];
}
tsprevday[nstepinaDay-1] = TSURFs;
taveprevday[nstepinaDay-1]= Tave;
//if((uebCellY + uebCellX) == 0)
//printf("Us = %f Ws = %Ws", Us, Ws);
OutArr[0] = Us;
OutArr[1] = Ws;
OutArr[2] = statev[2];
OutArr[3] = Pr;
OutArr[4]=Ps;
OutArr[5]=Alb;
OutArr[6]=QHs;
OutArr[7]=QEs;
OutArr[8]= Es;
OutArr[9]=SWIT;
OutArr[10]=QMs;
OutArr[11]=Q;
OutArr[12]= FM;
OutArr[13]=Tave;
OutArr[14]=TSURFs;
OutArr[15]=cumP;
OutArr[16]=cumEs;
OutArr[17]=cumMr;
OutArr[18]=Qnet;
OutArr[19]=smelt;
OutArr[20]=refDepth;
OutArr[21]=totalRefDepth;
OutArr[22]=cf;
OutArr[23]=Taufb;
OutArr[24]=Taufd;
OutArr[25]=Qsib;
OutArr[26]=Qsid;
OutArr[27]=Taub;
OutArr[28]=Taud;
OutArr[29]=Qsns;
OutArr[30]=Qsnc;
OutArr[31]=Qlns;
OutArr[32]=Qlnc ;
OutArr[33]=Vz;
OutArr[34]=Rkinsc;
OutArr[35]=Rkinc;
OutArr[36]=Inmax;
OutArr[37]=intc;
OutArr[38]=ieff;
OutArr[39]=Ur;
OutArr[40]=Wc;
OutArr[41]=Tc;
OutArr[42]=Tac;
OutArr[43]=QHc;
OutArr[44]=QEc;
OutArr[45]=Ec;
OutArr[46]=Qpc;
OutArr[47]=Qmc;
OutArr[48]=Mc;
OutArr[49]=FMc;
OutArr[50]=SWIGM;
OutArr[51]=SWISM;
OutArr[52]=SWIR;
//2 continue
statev[0]=Us;
statev[1]=Ws;
statev[4]=refDepth;
statev[5]=totalRefDepth;
statev[3]= Wc ; // Added vinod
outv[0]=Pr;
outv[1]=Ps;
outv[2]=Alb;
outv[3]=QHs;
outv[4]=QEs;
outv[5]=Es;
outv[6]=Mr;
outv[7]=QMs;
outv[8]=Q;
outv[9]=FM;
outv[10]=Tave;
outv[11]=TSURFs;
outv[12]=Qnet;
outv[13]=smelt; // dgt 5/4/04
return;
}
//************************ Predictor CORRECTOR ***********************************
__host__ __device__ void uebCell::PREDICORRc ( float &Us, float &Ws, float &Wc, float Alb, float dt, float rid, float P, float Pr, float Ps, float Ta, float V, float RH, float Qsi, float Qli,
float atff, float cosZen, float EmC, float Ems, float *param, float *sitev, int iradfl, float Qnetob, int iTsMethod, float *mtime,
// Following variables are output
float &Tc, float &QHc, float &QEc, float &Ec, float &Qpc, float &Qmc, float &Mc, float &FMc,float &intc, float &Inmax, float &ieff, float &Ur, float &Cf,
float &Taufb, float &Taufd, float &Qsib, float &Qsid, float &Taub,float &Taud, float &Qsnc, float &Qsns, float &Qlnc, float &Qlns, float &Rkinc, float &Rkinsc, float &Vz, float &Tac,
// Just for testing
float &QHs, float &QEs,float &Es, float &QPs, float &MR, float &QMs, float &Q,float &FM, float &TSURFs, float &tave, float &Qnet, float &refDepth, float &totalRefDepth, float &smelt,
float &gsurf, float &Qlis )
{
float int1, Mc1, Mr1;
float smeltC, Wc1, FMc1,Ur1,Ec1,Tc1,Ws1,Us1,Q1,FM1,QHs1,QEs1, Es1, smelt1, TSURFs1, QMs1, Qnet1, Wc2, Ws2, Us2, Es2;
float Ae, rlf, r;
QFMc(Us,Ws,Wc,Alb,dt,rid,P,Pr,Ps,Ta,V,RH,Qsi,atff,Qli, cosZen,EmC,Ems,param,sitev,iradfl,Qnetob,iTsMethod,mtime,
Tc,QHc,QEc,Ec,Qpc,QPs,Qmc,Mc,FMc,intc,Inmax,ieff,Ur, Cf,Taufb,Taufd,Qsib,Qsid,Taub,Taud,Qsnc,Qsns,Qlnc,Qlns,Rkinc,
Rkinsc,Vz,TSURFs,Tac, tave,Qnet,QHs,QEs,Es,MR,QMs,Q,FM,refDepth,totalRefDepth, smelt,smeltC);
// PREDICTOR FOR CANOPY SNOW
Wc1 = Wc + dt*FMc;
if(Wc1 < 0)
{
Wc1 = 0.0;
FMc = (Wc1- Wc)/dt;
Ur = findMax (0.0, (intc-FMc-Ec-Mc));
Ec = findMax(0.0,(intc-FMc-Mc-Ur));
Mc = (intc-FMc-Ec-Ur);
FM = Pr+Ps-intc+Ur+Mc-MR-Es; // int,ur,Mc added here
}
// Save values so that they can be averaged for output
FMc1 = FMc;
int1 = intc;
Ur1 = Ur;
Mc1 = Mc;
Ec1 = Ec;
Tc1 = Tc;
// PREDICTOR FOR SUB-CANOPY SNOW
Ws1 = Ws + dt*FM;
if(Ws1 < 0)
{
Ws1=0.0;
PREHELP(Ws1,Ws,dt,FM,0.0,1.0,Ps,Pr,Es,Rho_w,H_f,Q,QMs,MR,QEs, Hne_u);
}
Us1 = Us + dt*Q;
Q1 = Q;
FM1 = FM;
// Save values so that they can be averaged for output
QHs1 = QHs;
QEs1 = QEs;
Es1 = Es;
Mr1 = MR;
smelt1 =smelt; //cdgt 5/4/04 surface melt smelt
QMs1 = QMs;
TSURFs1 = TSURFs;
Qnet1 = Qnet;
if(snowdgtvariteflag3 == 1)
{
cout<<"\n Predictor: Us1, Ws1, Ts1, Q1, FM1 "<<endl;
cout<<" "<< Us1<<" "<< Ws1<<" "<<TSURFs1<<" "<<Q1<<" "<<FM1<<endl<<endl;
}
QFMc(Us1,Ws1,Wc1,Alb,dt,rid,P,Pr,Ps,Ta,V,RH,Qsi,atff,Qli, cosZen,EmC,Ems,param,sitev,iradfl,Qnetob,iTsMethod,mtime,
Tc,QHc,QEc,Ec,Qpc,QPs,Qmc,Mc,FMc,intc,Inmax,ieff,Ur, Cf,Taufb,Taufd,Qsib,Qsid,Taub,Taud,Qsnc,Qsns,Qlnc,Qlns,Rkinc,
Rkinsc,Vz,TSURFs,Tac, tave,Qnet,QHs,QEs,Es,MR,QMs,Q,FM,refDepth,totalRefDepth, smelt,smeltC);
// CORRECTOR FOR CANOPY SNOW
Wc2 = Wc + dt/2.0*(FMc1 + FMc);
if(Wc2 < 0)
{
Wc2 = 0.0;
FMc = (Wc2- Wc)/dt*2-FMc1;
Ur = findMax(0.,(intc-FMc-Ec-Mc));
Ec = findMax(0.,(intc-FMc-Mc-Ur));
Mc = (intc-FMc-Ec-Ur);
FM = Pr + Ps-intc+Ur+Mc-MR-Es; // int,ur,Mc added here
}
intc = (int1 +intc)/2;
Ur = (Ur1+Ur)/2;
Mc = (Mc1+Mc)/2;
Ec = (Ec1+Ec)/2; // But Mc and Ec don't change
Wc = Wc2;
Tc = (Tc1+ Tc)/2;
FMc = (FMc1+FMc)/2;
// CORRECTOR FOR SUB_CANOPY SNOW
Ws2 = Ws + dt/2.0*(FM1 + FM);
if(Ws2 < 0)
{
Ws2 = 0.0;
PREHELP(Ws2,Ws,dt,FM,FM1,2.0,Ps,Pr,Es,Rho_w,H_f,Q,QMs,MR,QEs,Hne_u);
}
Us2 = Us + dt/2.0*(Q1 + Q);
if(snowdgtvariteflag3 == 1)
{
cout<<"\n Corrector: Us2, Ws2, Ts, Q, FM "<<endl;
cout<<" "<< Us2<<" "<< Ws2<<" "<<TSURFs<<" "<<Q<<" "<<FM<<endl<<endl;
}
// iterate to convergence to enhance stability
int niter = 1, imax = 5;
while ((abs(Ws2-Ws1) > wtol || abs(Us2-Us1) > utol) && (niter < imax))
{
Ws1 = Ws2;
Us1 = Us2;
Wc1 = Wc2;
QFMc(Us1,Ws1,Wc1,Alb,dt,rid,P,Pr,Ps,Ta,V,RH,Qsi,atff,Qli, cosZen,EmC,Ems,param,sitev,iradfl,Qnetob,iTsMethod,mtime,
Tc,QHc,QEc,Ec,Qpc,QPs,Qmc,Mc,FMc,intc,Inmax,ieff,Ur, Cf,Taufb,Taufd,Qsib,Qsid,Taub,Taud,Qsnc,Qsns,Qlnc,Qlns,Rkinc,
Rkinsc,Vz,TSURFs,Tac, tave,Qnet,QHs,QEs,Es,MR,QMs,Q,FM,refDepth,totalRefDepth, smelt,smeltC);
// CORRECTOR FOR CANOPY SNOW AGAIN
Wc2 = Wc + dt/2.0*(FMc1 + FMc);
if(Wc2 < 0)
{
Wc2 = 0.0;
FMc = (Wc2- Wc)/dt*2-FMc1;
Ur = findMax(0.0,(intc-FMc-Ec-Mc));
Ec = findMax(0.0,(intc-FMc-Mc-Ur));
Mc = (intc-FMc-Ec-Ur);
FM = Pr+Ps-intc+Ur+Mc-MR-Es; // int,ur,Mc added here
// FM = FM+ (FMc-Ec)
}
intc = (int1 +intc)/2;
Ur = (Ur1+Ur)/2;
Mc = (Mc1+Mc)/2;
Ec = (Ec1+Ec)/2;
Wc = Wc2;
Tc = (Tc1+ Tc)/2;
FMc = (FMc1+FMc)/2;
//dgt 5/4/04 surface melt smelt
// corrector again
Ws2 = Ws + dt/2.0*(FM1 + FM);
if(Ws2 < 0)
{
Ws2 = 0.0;
PREHELP(Ws2,Ws,dt,FM,FM1,2.0,Ps,Pr,Es,Rho_w,H_f,Q,QMs,MR,QEs,Hne_u);
}
Us2 = Us + dt/2.0*(Q1 + Q);
niter++;
if(niter >= imax) // had * steps to converge now hit it. What follows is Alb fix to numerical instability that results from
{ // nonlinearity when the snowpack is shallow and melting rapidly. If convergence does not occur when the snowpack is not melting (Alb very
// rare thing) I just accept the predictor corrector solution. //
// Modified by DGT 7/27/05 to add complete meltout condition .The quantities that this changes are w2, ub2, MR and QMs
// The fix first checks whether the added energy is sufficient to melt the snow completely. ifthis is the case then the snow disappears.
// In other cases we assume that the liquid fraction of the snow remains constant. This to some extent bypasses the melt outflow estimates.
// ae is added energy during the time step.
Ae = (Q1+Q+QMs1+QMs)*0.5*dt; // This fix is only physically sensible under melting conditions and when ae is positive and there is snow
if((Us > 0) && (Ae > 0) && (Ws > 0))
{
Es2=(Es+Es1)*0.5; // This is the average sublimation
// Check liquid fraction with added energy. ifthis is greater than 1 then all snow melts .Otherwise implement Alb solution assuming that the liquid fraction remains constant
rlf=(Us+Ae)/(Rho_w*Ws*H_f);
if(rlf >= 1.0)
{
MR = Ws/dt+(Ps+Pr-Es2); // Here snow disappears
if(MR < 0 ) // Force this to not go negative. This can only occur if e2 is large compared to other terms. Setting w2=0 implicitly reduces e2.
MR = 0.0; // There is Alb resulting energy discrepancy due to Alb limitation on sublimation and latent heat flux
//This is ignored because once the snow is gone energy computations are not pertinent.
QMs=MR*Rho_w*H_f;
Ws2 = 0.0;
Us2 = Us + Ae - QMs*dt;
}
else // Determine the w/ub ratio at the beginning of the time step. Physically liquid fraction = ub/(Rho_w*w*H_f) and since Rho_w and H_f are constants
{ // keeping r=w/ub constant is equivalent to keeping liquid fraction constant. ifliquid fraction is constant this is constant.
r = Ws/Us; // Solve for ub2 and w2 that satisfy the three equations
// r=w2/ub2
// ub2=ub+Ae-Rho_w*H_f*MR*dt Energy balance the last term being the energy advected by melt
// w2=w+(Ps+prain-e2-MR)*dt Mass balance
// The unknowns in the above are ub2, w2 and m and the equations are linear. once the first eqn is multiplied by ub2, the solution is
Us2 = (Rho_w*H_f*(Ws+(Ps+Pr-Es2)*dt)-Ae-Us)/(Rho_w*H_f*r - 1);
Ws2=r*Us2;
if(Ws2 < 0) // Avoid negative W
Ws2 = 0.0;
MR = (Ws-Ws2)/dt -Es2 + Ps +Pr;
if(MR < 0 ) // Avoid negative MR
{
MR = 0.0;
Ws2 = Ws+ (Ps+Pr-Es2)/dt;
if(Ws2 < 0)
Ws2 = 0.0; // This can only occur ife2 is large compared to other terms. Setting w2=0 implicitly reduces e2. There is Alb resulting energy discrepancy due to
// Alb limitation on sublimation and latent heat flux. This is ignored because once the snow is gone energy computations are not pertinent.
}
QMs=MR*Rho_w*H_f;
Us2 = Us+Ae-QMs*dt; // redundant most of the time but recalc due to exceptions
}
// Check that nothing went wrong
if(MR < 0)
{
cout<<"Error - negative melt rate in snow"<<endl;
getchar();
}
if(Ws2 < 0)
{
cout<<"Error - negative w2 in snow"<<endl;
getchar();
}
Q = Ae/dt-QMs;
// Now set first pass values equal to final values to fake the averages below #$%^****take?
QMs1 = QMs;
Mr1 = MR;
Q1 = Q;
}
}
if(snowdgtvariteflag3 == 1)
{
//if( niter == 1)
cout<<endl<<"Iteration in pred-cor: niter, Us2, Ws2, Ts, Q, FM: "<<endl;
cout<<" "<<(niter-1)<<" "<<Us2<<" "<<Ws2<<" "<<TSURFs<<" "<<Q<<" "<< FM<<endl;
}
} //while ((abs(Ws2-Ws1) > wtol || abs(Us2-Us1) > utol) && (niter < imax)) //go to 1
Ws = Ws2;
Us = Us2;
// average values from two time steps for output. This is done for MR and e to ensure mass balance and the others for better physical comparisons
QHs = (QHs+QHs1)* 0.5;
QEs = (QEs+QEs1)* 0.5;
Es = (Es+Es1)* 0.5;
MR = (MR+Mr1)* 0.5;
QMs = (QMs+QMs1)* 0.5;
TSURFs = (TSURFs+TSURFs1) * 0.5;
Qnet = (Qnet + Qnet1) * 0.5;
Q = (Q+Q1) * 0.5;
smelt = (smelt+smelt1) * 0.5/(H_f*Rho_w); //cdgt 5/4/04 surface melt smelt .convert from energy KJ/m^2/hr to water depth m/hr of melt.
return;
}
// CALCULATE CANOPY MASS FLUX AT ANY INSTANT
__host__ __device__ void uebCell::QFMc(float Us, float Ws, float Wc, float A, float dt, float rid, float P, float Pr, float Ps, float Ta, float V, float RH, float Qsi, float atff, float Qli,
float cosZen, float EmC, float Ems, float *param, float *sitev, int iradfl, float Qnetob, int iTsMethod, float *mtime,
// Following variables are output
float &Tc, float &QHc, float &QEc, float &Ec, float &Qpc, float &Qps, float &Qmc, float &Mc, float &FMc, float &intc,float &Inmax, float &ieff, float &Ur, float &Cf, float &Taufb,
float &Taufd, float &Qsib, float &Qsid, float &Taub, float &Taud, float &Qsnc, float &Qsns, float &Qlnc, float &Qlns, float &Rkinc, float &Rkinsc, float &Vz, float &TSURFs, float &Tac,
// Just for testing
float &tave, float &qnet, float &QHs, float &QEs, float &Es, float &MR, float &QMs, float &Q, float &FM, float &refDepth, float &totalRefDepth, float &Smelt, float &smeltc )
{
float TAK, RHOA, rhom, fKappaS, ds, TherC, Zm,Fs, Qp, Qc1, Qc2 ;
float d, Z0c, Rimax, Rcastar, var_a, var_b, fkappaS, Betab,Betad, Qlis, Ess, Esc, QH, QE, E;
float Tssk, Tck;
//not used-but not deleted yet
//#$%____6.11.13
float Hcan, Ac;
// DOUBLE PRECISION Ur
// Parameters
Ems=param[2]; // emmissivity of snow [nominally 0.99],
float cg =param[3], // Ground heat capacity [nominally 2.09 KJ/kg/C],
rho=param[6], // Snow Density [Nominally 450 kg/m^3],
rhog=param[7], // Soil Density [nominally 1700 kg/m^3],
lc=param[8], // Liquid holding capacity of snow [0.05],
ks=param[9], // Snow Saturated hydraulic conductivity [160 m/hr],
de=param[10], // Thermally active depth of soil [0.4 m],
lans= param[14], // the thermal conductivity of fresh [dry], snow [0.0576 kJ/m/k/hr],
rd1= param[17], // Apmlitude correction coefficient of heat conduction [1],
gsurf=param[21], // The fraction of surface melt that runs off [e.g. from a glacier],
// cdgt gsurf added for modeling surface runoff from a glacier
// Site variables
Apr = sitev[1], // Atmospheric Pressure [Pa],
qg = sitev[2], // Ground heat flux [KJ/m^2/hr], This is more logically an
Cc = sitev[4], // Canopy Coverage
LAI = sitev[6]; // Leaf Area Index
//the following is passed to INTERCEPT instead of param(27)==param[26], same for cc
float Uc = param[26]; // Unloading rate coefficient (Per hour) (Hedstrom and pomeroy, 1998)
// To ensure all temperatures in kelvin
TAK = Ta + T_k;
RHOA = Apr / (Ra_g*TAK); // Density of Air in kg/m3 ifAPr in Pa
rhom = lc * rho;
// Some computations for conductivity
fKappaS = lans/(rho*C_s); // lans= lamda= thermao conductivity
ds = sqrt(2 * fKappaS /W1da_y); // fkappas =k= diffusivity
TherC = lans /(ds * rd1 *rho *C_s); // In QFM, related to thermal conductivity , lambda, of snow (Rs in Ori)
float EA = svpw(Ta) *RH; // The saturation vapour pressure over water is used
// because most instruments report relative humidity relative to water.
// Fraction of snow on canopy [Dickinson et. al (1993) eqn (50a)]
if(Inmax == 0.) //(When LAI is zero for open area model)
Fs= 0.0;
else
Fs = powf((Wc/Inmax),(2.0/3.0));
if(Fs > 1)
Fs=1;
INTERCEPT(Ta, LAI, P, Wc, dt, Inmax, Uc, Cc, ieff,Ur,intc);
/*param[26] = Uc;
sitev[4] = Cc;*/
// Total heat advected by precipitation is
Qp = QPF(Pr,Ta, T_0, Ps,Rho_w, H_f, C_w, C_s);
// Heat advected by precipitaion on canopy snow and sub-canopy snow is
if(P > 0)
{
if(Wc > 0)
{
Qpc = intc/P * Qp; // Energy from precipitaiton that hits the canopy snow
Qps = Qp - Qpc; // Energy advected by precipitaion that passes through canopy gap and thoroughfall from canopy
}
else
{
Qpc = 0.0;
Qps = ((P - intc)/P) * Qp;
}
}
else
{
Qpc = 0.0;
Qps = 0.0;
}
tave = TAVG (Us,Ws, Rho_w, C_s, T_0, rhog, de, cg, H_f);
//cout<<tave<<endl;
//yjs as described as below, the original UEB does not consider the refreezing. in this
// change, the model will consider the refreezing effect starting from the top to the bottom.
// Here is the predictor.
//yjs the method is: refreezing can be modeled ifthe Us is greater than 0.0 without any precipiation,
// meanwhile the total refreezing depth in the snowpack is less than the Refreezing depth times the daily damping of wet snow.
// if(Wc.EQ.0.and.p.EQ.0.) THEN // When there is no snow in the canopy
// Tc = Ta
// ELSE
// Tc = 0.0 // First assume snow is melting and then ifresult is negative - calculate canopy temperature having determined snow is not melting
// ENDIF
//********** To Calculate Refr Depth
if( (Us > 0) && (Ps <= 0) && (Pr <= 0) && (totalRefDepth <= rd1*ds) && (Ws > 0))
{
Qc1= QcEst(Ws,P,T_k,Tck,V,Zm,d,Z0c,Rimax,Rcastar,Cf,Fs, Qli,Hcan,Vz,Ta,RH,Rkinsc,Qps,T_0,Ps,Qsi,atff,cosZen, Apr,TAK, EA, A, Ac, Wc,Inmax, Qnetob,iradfl,param,sitev );
Qc2= QcEst(Ws,P,T_k -0.01,Tck,V,Zm,d,Z0c,Rimax,Rcastar,Cf,Fs, Qli,Hcan,Vz,Ta,RH,Rkinsc,Qps,T_0,Ps,Qsi,atff,cosZen, Apr,TAK, EA, A, Ac,Wc,Inmax, Qnetob,iradfl,param,sitev );
Grad(Qc1,Qc2,0.0,-0.01, var_a, var_b);
refDepth = refDep(lans,var_a, var_b, H_f, rhom, dt, refDepth); //refreezing depth
}
else
refDepth=0.0;
// call Temperature
TSURFs= SRFTMPSC (Tssk, Us,Ws,Wc,A,dt,P,Pr,Ps,Ta,V,RH,Qsi,atff,Cf, Qli,cosZen,EmC,Ems,param,sitev,iradfl,Qnetob,iTsMethod,mtime,
Qpc,Qps, Inmax, Rkinc,Rkinsc,Vz,Tc,T_k,TAK,EA,RHOA, fkappaS,rho,TherC,Fs, tave,refDepth,Smelt, smeltc); // This will give me Tsurf, Tc, and smeltc
//cout<<TSURFs<<endl;
if(iradfl != 1) // if iradfl==1 Go to 13 // To avoid these steps ifthe net radiation is input
{
PSOLRAD(Qsi,atff,param,Cf,Taufb,Taufd,Qsib,Qsid); // Output variables:
TRANSRADCAN (cosZen,sitev,param, Betab,Betad,Taub,Taud); // Output variables:
NETSOLRAD(Ta,A,Betab,Betad,Wc,Taub,Taud, Qsib,Qsid,param,Fs, Qsns,Qsnc ); // Output: Qsns,Qsnc (Net subcanopy, canopy solar radiation)
NETLONGRAD(RH,Ta,TSURFs,Tc,T_k,Fs,EmC,Ems,SB_c,Cf,sitev, Qli,param, Qlis,Qlns,Qlnc ); // Output: Qsns,Qsnc
}
/*13*/Ess = svpi(TSURFs);
Esc = svpi(Tc);
TURBFLUX(Ws,Wc,A,T_k,Tc,Ta,TSURFs,RH,V,EA,P,param,sitev, d,Z0c,Vz,Rkinc,Rkinsc,Tac,Fs,Ess,Esc, QHc,QEc,Ec,QHs,QEs,Es,QH,QE,E);
INTERCEPT(Ta,LAI,P,Wc,dt,Inmax,Uc,Cc, ieff,Ur,intc); // Output variables
// melt from the canopy
Qmc = smeltc;
Mc = Qmc/(Rho_w*H_f);
// Ridistribution of intercepted snow subtracting in mass balancep
// We are applying same amount as unloading is lost from the canopy from the wind redistribution
// Rid = Ur
//***************** UPDATING THE MASS BALANCE AT CANOPY
/*12*/ FMc = intc-Ec-Mc-Ur;
//***************** UPDATING THE MASS and ENERGY BALANCE AT SUB-CANOPY
MR = FMELT(Us,Rho_w,Ws,H_f,lc, rid,ks,Pr); //yjs Add a fraction to reduce the evaporation after snow gone // MR in m/hr
QMs = MR*Rho_w*(H_f+(tave-T_0)*C_w); // Include advection of
// meltwater/rain that is at tave so that the model does not
// crash when there is no snow and it rains.
// QMs in kj/m2/hr
// dgt 5/4/04 Add surface melt that runs off to melt runoff and melt energy so that energy and mass balances
// are still correct
MR = MR + Smelt/(H_f*Rho_w)*gsurf;
QMs=QMs+Smelt*gsurf;
if(iradfl == 0)
// QNET = QSI*(1.0-A)+QLNET
qnet = Qsns+Qlns; // At sub canopy snow
else
qnet = Qnetob;
// if(Ws.EQ.0.and. p.EQ.0.) THEN // vinod added to orgi UEB
// Es = 0.
// MR = 0.
// ENDIF
Q = qnet + Qps + qg + QHs + QEs-QMs;
FM =1.0*(Pr+Ps)-intc +Ur +Mc -MR -Es; // int,ur,Mc added here
return;
}
//************************* SRFTMP () *********************************
// COMPUTE THE SURFACE TEMPERATURE OF SNOW
__host__ __device__ float uebCell::SRFTMPSC(float &Tssk, float Us, float Ws, float Wc, float A, float dt, float P, float Pr, float Ps, float Ta, float V, float RH, float Qsi, float atff, float cf, float Qli, float cosZen,
float EmC,float Ems,float *param,float *sitev,int iradfl,float Qnetob,int iTsMethod,float *mtime,float Qpcin,float Qpsin,float Inmax,float Rkinc,float Rkinsc,float Vz,
float &Tc,float Tk,float &Tak,float &EA,float &RHOA,float &fkappaS,float &RHO,float &TherC,float &Fs,float &Tave,float &refDepth,float &smelt,float &smeltC
)
{
float F1, F2, F1ts,F1tc,F2ts,F2tc,J11, J12, J21, J22, delTs, delTc, SRFTMPSC_v;
float S1num, S2num, S1denom, S2denom; //
float Tssk1 , Tck1 , Tss, Tck , S1, S2, Tclast, Tslast, ERc, ER;
float Tlb, Tub, Flb, Fub;
int iterC, ibtowrite = 0;
float Tssk1p, Tck1p;
float TSURFs;
// assumed small increament to estimate the Jocobian matrix
delTs = 0.01;
delTc = 0.01;
//9.22.13
float f1minf2 = 1;
// Parameters
Ems=param[2]; // emmissivity of snow [nominally 0.99],
RHO = param[6]; // Snow Density [Nominally 450 kg/m^3],
float Cc = sitev[4], // Canopy Coverage
LAI = sitev[6]; // Leaf Area Index
// This version written on 4/23/97 by Charlie Luce solves directly the energy balance equation using Newtons method - avoiding the linearizations
// used previously. The derivative is evaluated numerically over the range ts to fff*ts where fff = 0.999
float tol_l = 0.005; //local tolerance
float fff = (273.0-tol_l)/273.0; // Scale the difference used for derivatives by the tolerance
Tak = Ta + Tk;
float Qps = Qpsin;
float Qpc = Qpcin; // store input variable locally without changing global value
if((Ws <= 0) && (Qps > 0))
Qps = 0.0;
//******** FOR OPEN AREA MODLING ********************************
if((LAI == 0) || (Cc == 0))
{
Tssk=Tak;
//goto labl18;
}
else
{
//************ SOLVING NON LINEAR EQUATION IN TWO DIMENSTION (newton's method using Jacobian matrix)*********
Tssk1 = Tak; // first approximation
Tck1 = Tak; // first approximation
int niter = 0;
/*15*/ while (niter < nitermax)
{
niter++;
F1 = SURFEBSC(Tssk1,Us,Ws,Wc,A,dt,P,Pr,Ps,Ta,V,RH,Fs,cf,Qli, Qsi,atff,cosZen,EmC,Ems,param,sitev,iradfl,Qnetob,iTsMethod,mtime,
Qpc,Qps,Inmax, Rkinc,Rkinsc,Vz,Tck1,Tk,Tak,EA,RHOA, fkappaS,RHO,TherC, TSURFs, Tave,refDepth);
//yjs add three value to reflect model control changes))
F2 = SURFEBC(Tck1,Us,Ws,Wc,A,dt,P,Pr,Ps,Ta,V,RH,Fs,cf,Qli, Qsi,atff,cosZen,EmC,Ems,param,sitev,iradfl,Qnetob,iTsMethod,mtime,
Qpc,Qps,Inmax, Rkinc,Rkinsc,Vz,Tssk1,Tk,Tak,EA,RHOA, fkappaS,RHO,TherC, TSURFs,Tave,refDepth); //yjs add three value to reflect model control changes))
Tssk1p = Tssk1 + delTs;
Tck1p = Tck1 + delTc;
F1ts = SURFEBSC (Tssk1p,Us,Ws,Wc,A,dt,P,Pr,Ps,Ta,V,RH,Fs,cf, Qli,Qsi,atff,cosZen,EmC,Ems,param,sitev,iradfl,Qnetob, iTsMethod,mtime,
Qpc,Qps,Inmax, Rkinc,Rkinsc,Vz,Tck1, Tk,Tak,EA,RHOA, fkappaS,RHO,TherC, TSURFs,Tave,refDepth);
F1tc = SURFEBSC (Tssk1,Us,Ws,Wc,A,dt,P,Pr,Ps,Ta,V,RH,Fs,cf,Qli, Qsi,atff,cosZen,EmC,Ems,param,sitev,iradfl,Qnetob,iTsMethod,mtime,
Qpc,Qps,Inmax, Rkinc,Rkinsc,Vz,Tck1p,Tk,Tak,EA,RHOA, fkappaS,RHO,TherC, TSURFs,Tave,refDepth);
F2ts = SURFEBC (Tck1,Us,Ws,Wc,A,dt,P,Pr,Ps,Ta,V,RH,Fs,cf,Qli, Qsi,atff,cosZen,EmC,Ems,param,sitev,iradfl,Qnetob,iTsMethod,mtime,
Qpc,Qps,Inmax, Rkinc,Rkinsc,Vz,Tssk1p,Tk,Tak,EA,RHOA, fkappaS,RHO,TherC, TSURFs,Tave,refDepth);
F2tc = SURFEBC (Tck1p,Us,Ws,Wc,A,dt,P,Pr,Ps,Ta,V,RH,Fs,cf,Qli, Qsi,atff,cosZen,EmC,Ems,param,sitev,iradfl,Qnetob,iTsMethod,mtime,
Qpc,Qps,Inmax, Rkinc,Rkinsc,Vz,Tssk1,Tk,Tak,EA,RHOA, fkappaS,RHO,TherC, TSURFs,Tave,refDepth);
// Jacobian matrix
J11 = (F1ts-F1)/delTs;
J12 = (F1tc-F1)/delTc;
J21 = (F2ts-F2)/delTs;
J22 = (F2tc-F2)/delTc;
//9.21.13
S1num = F1*J22-F2*J12;
S1denom = J12*J21-J22*J11;
S2num = F2*J11-F1*J21;
S2denom = J12*J21-J22*J11;
S1 = (F1*J22-F2*J12) / (J12*J21-J22*J11); //S1num/S1denom; //
S2 = (F2*J11-F1*J21) / (J12*J21-J22*J11); // S2num/S2denom; //