-
Notifications
You must be signed in to change notification settings - Fork 0
/
SoilTemperatureMod.F90
5129 lines (4539 loc) · 285 KB
/
SoilTemperatureMod.F90
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
module SoilTemperatureMod
#include "shr_assert.h"
!-----------------------------------------------------------------------
! !DESCRIPTION:
! Calculates snow and soil temperatures including phase change
!
! !USES:
use shr_kind_mod , only : r8 => shr_kind_r8
use shr_log_mod , only : errMsg => shr_log_errMsg
use shr_infnan_mod , only : nan => shr_infnan_nan, assignment(=)
use decompMod , only : bounds_type
use abortutils , only : endrun
use perf_mod , only : t_startf, t_stopf
use clm_varctl , only : iulog
use UrbanParamsType , only : urbanparams_type
use atm2lndType , only : atm2lnd_type
use CanopyStateType , only : canopystate_type
use WaterfluxType , only : waterflux_type
use WaterstateType , only : waterstate_type
use SolarAbsorbedType , only : solarabs_type
use SoilStateType , only : soilstate_type
use EnergyFluxType , only : energyflux_type
use TemperatureType , only : temperature_type
use TopounitDataType , only : top_af
use LandunitType , only : lun_pp
use LandunitDataType , only : lun_es, lun_ef
use ColumnType , only : col_pp
use ColumnDataType , only : col_es, col_ef, col_ws, col_wf
use VegetationType , only : veg_pp
use VegetationDataType, only : veg_ef, veg_wf
!
! !PUBLIC TYPES:
implicit none
save
!
! !PUBLIC MEMBER FUNCTIONS:
public :: SoilTemperature
!
! -> SoilTemperature: soil/snow and ground temperatures
! -> SoilTermProp thermal conductivities and heat capacities
! -> Tridiagonal tridiagonal matrix solution
! -> PhaseChange phase change of liquid/ice contents
!
! (1) Snow and soil temperatures
! o The volumetric heat capacity is calculated as a linear combination
! in terms of the volumetric fraction of the constituent phases.
! o The thermal conductivity of soil is computed from
! the algorithm of Johansen (as reported by Farouki 1981), and the
! conductivity of snow is from the formulation used in
! SNTHERM (Jordan 1991).
! o Boundary conditions:
! F = Rnet - Hg - LEg (top), F= 0 (base of the soil column).
! o Soil / snow temperature is predicted from heat conduction
! in 10 soil layers and up to 5 snow layers.
! The thermal conductivities at the interfaces between two
! neighboring layers (j, j+1) are derived from an assumption that
! the flux across the interface is equal to that from the node j
! to the interface and the flux from the interface to the node j+1.
! The equation is solved using the Crank-Nicholson method and
! results in a tridiagonal system equation.
! (2) Phase change
!
! The following is only public for the sake of unit testing; it should not be called
! directly by CLM code outside this module
public :: ComputeGroundHeatFluxAndDeriv ! Computes G and dG/dT on surface of standing water, snow and soil
public :: ComputeHeatDiffFluxAndFactor ! Heat diffusion at layer interface and factor used in setting up of banded matrix
public :: SetRHSVec ! Sets up the RHS vector for the numerical solution of temperature for snow/standing-water/soil
public :: SetRHSVec_Snow ! Sets up the RHS vector corresponding to snow layers for Urban+Non-Urban columns
public :: SetRHSVec_SnowUrban ! Sets up the RHS vector corresponding to snow layers for Urban columns
public :: SetRHSVec_SnowUrbanNonRoad ! Sets up the RHS vector corresponding to snow layers for Urban columns that are sunwall, shadewall, and roof columns
public :: SetRHSVec_SnowUrbanRoad ! Sets up the RHS vector corresponding to snow layers for Urban columns that are pervious, and impervious columns
public :: SetRHSVec_SnowNonUrban ! Sets up the RHS vector corresponding to snow layers for Non-Urban columns
public :: SetRHSVec_StandingSurfaceWater ! Sets up the RHS vector corresponding to standing water layers for Urban+Non-Urban columns
public :: SetRHSVec_Soil ! Sets up the RHS vector corresponding to soil layers for Urban+Non-Urban columns
public :: SetRHSVec_SoilUrban ! Sets up the RHS vector corresponding to soil layers for Urban columns
public :: SetRHSVec_SoilUrbanNonRoad ! Sets up the RHS vector corresponding to soil layers for Urban columns that are pervious, and impervious columns
public :: SetRHSVec_SoilUrbanRoad ! Sets up the RHS vector corresponding to soil layers for Urban columns that are pervious, and impervious columns
public :: SetRHSVec_SoilNonUrban ! Sets up the RHS vector corresponding to soil layers for Non-Urban columns
public :: SetRHSVec_Soil_StandingSurfaceWater ! Adds contribution from standing water in the RHS vector corresponding to soil layers
public :: SetMatrix ! Sets up the matrix for the numerical solution of temperature for snow/standing-water/soil
public :: AssembleMatrixFromSubmatrices ! Assemble the full matrix from submatrices.
public :: SetMatrix_Snow ! Set up the matrix entries corresponding to snow layers for Urban+Non-Urban columns
public :: SetMatrix_SnowUrban ! Set up the matrix entries corresponding to snow layers for Urban column
public :: SetMatrix_SnowUrbanNonRoad ! Set up the matrix entries corresponding to snow layers for Urban column that are sunwall, shadewall, and roof columns
public :: SetMatrix_SnowUrbanRoad ! Set up the matrix entries corresponding to snow layers for Urban column that are pervious, and impervious columns
public :: SetMatrix_SnowNonUrban ! Set up the matrix entries corresponding to snow layers for Non-Urban column
public :: SetMatrix_Snow_Soil ! Set up the matrix entries corresponding to snow-soil interaction
public :: SetMatrix_Snow_SoilUrban ! Set up the matrix entries corresponding to snow-soil interaction for Urban column
public :: SetMatrix_Snow_SoilUrbanNonRoad ! Set up the matrix entries corresponding to snow-soil interaction for Urban column that are sunwall, shadewall, and roof columns
public :: SetMatrix_Snow_SoilUrbanRoad ! Set up the matrix entries corresponding to snow-soil interaction for Urban column that are pervious, and impervious columns
public :: SetMatrix_Snow_SoilNonUrban ! Set up the matrix entries corresponding to snow-soil interaction for Non-Urban column
public :: SetMatrix_Soil ! Set up the matrix entries corresponding to soil layers for Urban+Non-Urban columns
public :: SetMatrix_SoilUrban ! Set up the matrix entries corresponding to soil layers for Urban column
public :: SetMatrix_SoilUrbanNonRoad ! Set up the matrix entries corresponding to soil layers for Urban column that are sunwall, shadewall, and roof columns
public :: SetMatrix_SoilUrbanRoad ! Set up the matrix entries corresponding to soil layers for Urban column that are pervious, and impervious columns
public :: SetMatrix_SoilNonUrban ! Set up the matrix entries corresponding to soil layers for Non-Urban column
public :: SetMatrix_Soil_Snow ! Set up the matrix entries corresponding to soil-snow interction for Urban+Non-Urban columns
public :: SetMatrix_Soil_SnowUrban ! Set up the matrix entries corresponding to soil-snow interction for Urban column
public :: SetMatrix_Soil_SnowUrbanNonRoad ! Set up the matrix entries corresponding to soil-snow interction for Urban column that are sunwall, shadewall, and roof columns
public :: SetMatrix_Soil_SnowUrbanRoad ! Set up the matrix entries corresponding to soil-snow interction for Urban column that are pervious, and impervious columns
public :: SetMatrix_Soil_SnowNonUrban ! Set up the matrix entries corresponding to soil-snow interction for Non-Urban column
public :: SetMatrix_StandingSurfaceWater ! Set up the matrix entries corresponding to standing surface water
public :: SetMatrix_StandingSurfaceWater_Soil ! Set up the matrix entries corresponding to standing surface water-soil interaction
public :: SetMatrix_Soil_StandingSurfaceWater ! Set up the matrix entries corresponding to soil-standing surface water interction
public :: init_soil_temperature ! Initializes soil tempreature model
!
! !PRIVATE MEMBER FUNCTIONS:
private :: SoilThermProp ! Set therm conduct. and heat cap of snow/soil layers
private :: PhaseChangeH2osfc ! When surface water freezes move ice to bottom snow layer
private :: PhaseChange_beta ! Calculation of the phase change within snow and soil layers
integer, parameter :: default_thermal_model = 0
integer, parameter :: petsc_thermal_model = 1
integer :: thermal_model
real(r8), private, parameter :: thin_sfclayer = 1.0e-6_r8 ! Threshold for thin surface layer
!-----------------------------------------------------------------------
contains
!-----------------------------------------------------------------------
subroutine init_soil_temperature()
!
!DESCRIPTION
! Initializes the soil tempreature model
!
use clm_varctl, only : use_petsc_thermal_model
! !ARGUMENTS:
if (.not.use_petsc_thermal_model) then
thermal_model = default_thermal_model
else
thermal_model = petsc_thermal_model
endif
end subroutine init_soil_temperature
!-----------------------------------------------------------------------
subroutine SoilTemperature(bounds, num_urbanl, filter_urbanl, num_nolakec, filter_nolakec, &
atm2lnd_vars, urbanparams_vars, canopystate_vars, waterstate_vars, waterflux_vars,&
solarabs_vars, soilstate_vars, energyflux_vars, temperature_vars)
!
! !DESCRIPTION:
! Snow and soil temperatures including phase change
! o The volumetric heat capacity is calculated as a linear combination
! in terms of the volumetric fraction of the constituent phases.
! o The thermal conductivity of soil is computed from
! the algorithm of Johansen (as reported by Farouki 1981), and the
! conductivity of snow is from the formulation used in
! SNTHERM (Jordan 1991).
! o Boundary conditions:
! F = Rnet - Hg - LEg (top), F= 0 (base of the soil column).
! o Soil / snow temperature is predicted from heat conduction
! in 10 soil layers and up to 5 snow layers.
! The thermal conductivities at the interfaces between two
! neighboring layers (j, j+1) are derived from an assumption that
! the flux across the interface is equal to that from the node j
! to the interface and the flux from the interface to the node j+1.
! The equation is solved using the Crank-Nicholson method and
! results in a tridiagonal system equation.
!
! !USES:
use clm_time_manager , only : get_step_size
use clm_varpar , only : nlevsno, nlevgrnd, nlevurb
use clm_varctl , only : iulog
use clm_varcon , only : cnfac, cpice, cpliq, denh2o
use landunit_varcon , only : istice, istice_mec, istsoil, istcrop
use column_varcon , only : icol_roof, icol_sunwall, icol_shadewall, icol_road_perv, icol_road_imperv
use landunit_varcon , only : istwet, istice, istice_mec, istsoil, istcrop
use BandDiagonalMod , only : BandDiagonal
use ExternalModelConstants , only : EM_ID_PTM
use ExternalModelConstants , only : EM_PTM_TBASED_SOLVE_STAGE
use ExternalModelInterfaceMod, only : EMI_Driver
!
! !ARGUMENTS:
type(bounds_type) , intent(in) :: bounds
integer , intent(in) :: num_nolakec ! number of column non-lake points in column filter
integer , intent(in) :: filter_nolakec(:) ! column filter for non-lake points
integer , intent(in) :: num_urbanl ! number of urban landunits in clump
integer , intent(in) :: filter_urbanl(:) ! urban landunit filter
type(atm2lnd_type) , intent(in) :: atm2lnd_vars
type(urbanparams_type) , intent(in) :: urbanparams_vars
type(canopystate_type) , intent(in) :: canopystate_vars
type(waterstate_type) , intent(inout) :: waterstate_vars
type(waterflux_type) , intent(inout) :: waterflux_vars
type(soilstate_type) , intent(inout) :: soilstate_vars
type(solarabs_type) , intent(inout) :: solarabs_vars
type(energyflux_type) , intent(inout) :: energyflux_vars
type(temperature_type) , intent(inout) :: temperature_vars
!
! !LOCAL VARIABLES:
integer :: j,c,l,g,pi ! indices
integer :: fc ! lake filtered column indices
integer :: fl ! urban filtered landunit indices
integer :: jtop(bounds%begc:bounds%endc) ! top level at each column
real(r8) :: dtime ! land model time step (sec)
real(r8) :: cv (bounds%begc:bounds%endc,-nlevsno+1:nlevgrnd) ! heat capacity [J/(m2 K)]
real(r8) :: tk (bounds%begc:bounds%endc,-nlevsno+1:nlevgrnd) ! thermal conductivity [W/(m K)]
real(r8) :: fn (bounds%begc:bounds%endc,-nlevsno+1:nlevgrnd) ! heat diffusion through the layer interface [W/m2]
real(r8) :: fn1(bounds%begc:bounds%endc,-nlevsno+1:nlevgrnd) ! heat diffusion through the layer interface [W/m2]
real(r8) :: dzm ! used in computing tridiagonal matrix
real(r8) :: dzp ! used in computing tridiagonal matrix
real(r8) :: sabg_lyr_col(bounds%begc:bounds%endc,-nlevsno+1:1) ! absorbed solar radiation (col,lyr) [W/m2]
real(r8) :: eflx_gnet_top ! net energy flux into surface layer, pft-level [W/m2]
real(r8) :: hs_top(bounds%begc:bounds%endc) ! net energy flux into surface layer (col) [W/m2]
logical :: cool_on(bounds%begl:bounds%endl) ! is urban air conditioning on?
logical :: heat_on(bounds%begl:bounds%endl) ! is urban heating on?
real(r8) :: fn_h2osfc(bounds%begc:bounds%endc) ! heat diffusion through standing-water/soil interface [W/m2]
real(r8) :: dz_h2osfc(bounds%begc:bounds%endc) ! height of standing surface water [m]
real(r8) :: tvector_nourbanc(bounds%begc:bounds%endc,-nlevsno:nlevgrnd) ! initial temperature solution for non-urban columns [Kelvin]
real(r8) :: tvector_urbanc(bounds%begc:bounds%endc,-nlevsno:nlevgrnd) ! initial temperature solution for urban columns [Kelvin]
real(r8) :: tk_h2osfc(bounds%begc:bounds%endc) ! thermal conductivity of h2osfc [W/(m K)] [col]
real(r8) :: dhsdT(bounds%begc:bounds%endc) ! temperature derivative of "hs" [col]
real(r8) :: hs_soil(bounds%begc:bounds%endc) ! heat flux on soil [W/m2]
real(r8) :: hs_top_snow(bounds%begc:bounds%endc) ! heat flux on top snow layer [W/m2]
real(r8) :: hs_h2osfc(bounds%begc:bounds%endc) ! heat flux on standing water [W/m2]
integer :: jbot(bounds%begc:bounds%endc) ! bottom level at each column
integer :: num_nolakec_and_nourbanc
integer :: num_nolakec_and_urbanc
integer :: num_filter_lun
integer, pointer :: filter_nolakec_and_nourbanc(:)
integer, pointer :: filter_nolakec_and_urbanc(:)
integer, pointer :: filter_lun(:)
logical :: urban_column
logical :: update_temperature
!Jing Tao added:
real(r8) :: fn_mod(bounds%begc:bounds%endc,-nlevsno+1:nlevgrnd)
!-----------------------------------------------------------------------
associate( &
snl => col_pp%snl , & ! Input: [integer (:) ] number of snow layers
zi => col_pp%zi , & ! Input: [real(r8) (:,:) ] interface level below a "z" level (m)
dz => col_pp%dz , & ! Input: [real(r8) (:,:) ] layer depth (m)
z => col_pp%z , & ! Input: [real(r8) (:,:) ] layer thickness (m)
t_building_max => urbanparams_vars%t_building_max , & ! Input: [real(r8) (:) ] maximum internal building temperature (K)
t_building_min => urbanparams_vars%t_building_min , & ! Input: [real(r8) (:) ] minimum internal building temperature (K)
frac_veg_nosno => canopystate_vars%frac_veg_nosno_patch , & ! Input: [integer (:) ] fraction of vegetation not covered by snow (0 OR 1) [-]
frac_sno_eff => col_ws%frac_sno_eff , & ! Input: [real(r8) (:) ] eff. fraction of ground covered by snow (0 to 1)
frac_sno => col_ws%frac_sno , & ! Input: [real(r8) (:) ] fraction of ground covered by snow (0 to 1)
snow_depth => col_ws%snow_depth , & ! Input: [real(r8) (:) ] snow height (m)
h2osfc => col_ws%h2osfc , & ! Input: [real(r8) (:) ] surface water (mm)
frac_h2osfc => col_ws%frac_h2osfc , & ! Input: [real(r8) (:) ] fraction of ground covered by surface water (0 to 1)
qflx_evap_soi => veg_wf%qflx_evap_soi , & ! Input: [real(r8) (:) ] soil evaporation (mm H2O/s) (+ = to atm)
qflx_tran_veg => veg_wf%qflx_tran_veg , & ! Input: [real(r8) (:) ] vegetation transpiration (mm H2O/s) (+ = to atm)
qflx_ev_snow => veg_wf%qflx_ev_snow , & ! Input: [real(r8) (:) ] evaporation flux from snow (W/m**2) [+ to atm]
qflx_ev_soil => veg_wf%qflx_ev_soil , & ! Input: [real(r8) (:) ] evaporation flux from soil (W/m**2) [+ to atm]
qflx_ev_h2osfc => veg_wf%qflx_ev_h2osfc , & ! Input: [real(r8) (:) ] evaporation flux from h2osfc (W/m**2) [+ to atm]
sabg_soil => solarabs_vars%sabg_soil_patch , & ! Input: [real(r8) (:) ] solar radiation absorbed by soil (W/m**2)
sabg_snow => solarabs_vars%sabg_snow_patch , & ! Input: [real(r8) (:) ] solar radiation absorbed by snow (W/m**2)
sabg_chk => solarabs_vars%sabg_chk_patch , & ! Output: [real(r8) (:) ] sum of soil/snow using current fsno, for balance check
sabg_lyr => solarabs_vars%sabg_lyr_patch , & ! Input: [real(r8) (:,:) ] absorbed solar radiation (pft,lyr) [W/m2]
sabg => solarabs_vars%sabg_patch , & ! Input: [real(r8) (:) ] solar radiation absorbed by ground (W/m**2)
htvp => col_ef%htvp , & ! Input: [real(r8) (:) ] latent heat of vapor of water (or sublimation) [j/kg]
cgrnd => veg_ef%cgrnd , & ! Input: [real(r8) (:) ] deriv. of soil energy flux wrt to soil temp [w/m2/k]
dlrad => veg_ef%dlrad , & ! Input: [real(r8) (:) ] downward longwave radiation blow the canopy [W/m2]
eflx_sh_grnd => veg_ef%eflx_sh_grnd , & ! Input: [real(r8) (:) ] sensible heat flux from ground (W/m**2) [+ to atm]
eflx_lwrad_net => veg_ef%eflx_lwrad_net , & ! Input: [real(r8) (:) ] net infrared (longwave) rad (W/m**2) [+ = to atm]
eflx_sh_snow => veg_ef%eflx_sh_snow , & ! Input: [real(r8) (:) ] sensible heat flux from snow (W/m**2) [+ to atm]
eflx_sh_soil => veg_ef%eflx_sh_soil , & ! Input: [real(r8) (:) ] sensible heat flux from soil (W/m**2) [+ to atm]
eflx_sh_h2osfc => veg_ef%eflx_sh_h2osfc , & ! Input: [real(r8) (:) ] sensible heat flux from surface water (W/m**2) [+ to atm]
eflx_bot => col_ef%eflx_bot , & ! Input: [real(r8) (:) ] heat flux from beneath column (W/m**2) [+ = upward]
eflx_fgr12 => col_ef%eflx_fgr12 , & ! Input: [real(r8) (:) ] heat flux between soil layer 1 and 2 (W/m2)
eflx_fgr => col_ef%eflx_fgr , & ! Input: [real(r8) (:,:) ] (rural) soil downward heat flux (W/m2) (1:nlevgrnd)
eflx_gnet => veg_ef%eflx_gnet , & ! Output: [real(r8) (:) ] net ground heat flux into the surface (W/m**2)
eflx_building_heat => col_ef%eflx_building_heat , & ! Output: [real(r8) (:) ] heat flux from urban building interior to walls, roof (W/m**2)
eflx_urban_ac => col_ef%eflx_urban_ac , & ! Output: [real(r8) (:) ] urban air conditioning flux (W/m**2)
eflx_urban_heat => col_ef%eflx_urban_heat , & ! Output: [real(r8) (:) ] urban heating flux (W/m**2)
emg => col_es%emg , & ! Input: [real(r8) (:) ] ground emissivity
hc_soi => col_es%hc_soi , & ! Input: [real(r8) (:) ] soil heat content (MJ/m2) ! TODO: make a module variable
hc_soisno => col_es%hc_soisno , & ! Input: [real(r8) (:) ] soil plus snow plus lake heat content (MJ/m2) !TODO: make a module variable
tssbef => col_es%t_ssbef , & ! Input: [real(r8) (:,:) ] temperature at previous time step [K]
t_h2osfc => col_es%t_h2osfc , & ! Output: [real(r8) (:) ] surface water temperature
t_soisno => col_es%t_soisno , & ! Output: [real(r8) (:,:) ] soil temperature (Kelvin)
t_grnd => col_es%t_grnd , & ! Output: [real(r8) (:) ] ground surface temperature [K]
t_building => lun_es%t_building , & ! Output: [real(r8) (:) ] internal building temperature (K)
xmf => col_ef%xmf , & ! Output: [real(r8) (:) ] melting or freezing within a time step [kg/m2]
xmf_h2osfc => col_ef%xmf_h2osfc , & ! Output: [real(r8) (:) ] latent heat of phase change of surface water [col]
fact => col_es%fact , & ! Output: [real(r8) (:) ] used in computing tridiagonal matrix [col, lev]
c_h2osfc => col_es%c_h2osfc , & ! Output: [real(r8) (:) ] heat capacity of surface water [col]
begc => bounds%begc , &
endc => bounds%endc &
)
! Get step size
dtime = get_step_size()
! Restrict internal building temperature to between min and max
! and determine if heating or air conditioning is on
do fl = 1,num_urbanl
l = filter_urbanl(fl)
if (lun_pp%urbpoi(l)) then
cool_on(l) = .false.
heat_on(l) = .false.
if (t_building(l) > t_building_max(l)) then
t_building(l) = t_building_max(l)
cool_on(l) = .true.
heat_on(l) = .false.
else if (t_building(l) < t_building_min(l)) then
t_building(l) = t_building_min(l)
cool_on(l) = .false.
heat_on(l) = .true.
end if
end if
end do
! set up compact matrix for band diagonal solver, requires additional
! sub/super diagonals (1 each), and one additional row for t_h2osfc
jtop = -9999
do fc = 1,num_nolakec
c = filter_nolakec(fc)
jtop(c) = snl(c)
! compute jbot
if ((col_pp%itype(c) == icol_sunwall .or. col_pp%itype(c) == icol_shadewall &
.or. col_pp%itype(c) == icol_roof) ) then
jbot(c) = nlevurb
else
jbot(c) = nlevgrnd
endif
end do
!
! Setup two new filters:
! - filter_nolakec_and_nourbanc: No Lakes + No Urban columns
! - filter_nolakec_and_urbanc : No Lakes + Urban columns
!
num_nolakec_and_nourbanc = 0
num_nolakec_and_urbanc = 0
do fc = 1,num_nolakec
c = filter_nolakec(fc)
l = col_pp%landunit(c)
if (lun_pp%urbpoi(l)) then
num_nolakec_and_urbanc = num_nolakec_and_urbanc + 1
else
num_nolakec_and_nourbanc = num_nolakec_and_nourbanc + 1
endif
enddo
allocate(filter_nolakec_and_nourbanc(num_nolakec_and_nourbanc))
allocate(filter_nolakec_and_urbanc( num_nolakec_and_urbanc ))
num_nolakec_and_nourbanc = 0
num_nolakec_and_urbanc = 0
do fc = 1,num_nolakec
c = filter_nolakec(fc)
l = col_pp%landunit(c)
if (lun_pp%urbpoi(l)) then
num_nolakec_and_urbanc = num_nolakec_and_urbanc + 1
filter_nolakec_and_urbanc(num_nolakec_and_urbanc) = c
else
num_nolakec_and_nourbanc = num_nolakec_and_nourbanc + 1
filter_nolakec_and_nourbanc(num_nolakec_and_nourbanc) = c
endif
end do
num_filter_lun = bounds%endl - bounds%begl + 1
allocate(filter_lun(num_filter_lun))
do fc = 1, num_filter_lun
filter_lun(fc) = bounds%begl + fc - 1
enddo
!------------------------------------------------------
! Compute ground surface and soil temperatures
!------------------------------------------------------
! Thermal conductivity and Heat capacity
tk_h2osfc(begc:endc) = nan
call SoilThermProp(bounds, num_nolakec, filter_nolakec, &
tk(begc:endc, :), &
cv(begc:endc, :), &
tk_h2osfc(begc:endc), &
urbanparams_vars, temperature_vars, waterstate_vars, soilstate_vars)
! Net ground heat flux into the surface and its temperature derivative
! Added a patches loop here to get the average of hs and dhsdT over
! all Patches on the column. Precalculate the terms that do not depend on PFT.
call ComputeGroundHeatFluxAndDeriv(bounds, num_nolakec, filter_nolakec, &
hs_h2osfc( begc:endc ), &
hs_top_snow( begc:endc ), &
hs_soil( begc:endc ), &
hs_top( begc:endc ), &
dhsdT( begc:endc ), &
sabg_lyr_col( begc:endc, -nlevsno+1: ), &
atm2lnd_vars, urbanparams_vars, canopystate_vars, waterstate_vars, &
waterflux_vars, solarabs_vars, energyflux_vars, temperature_vars)
! Determine heat diffusion through the layer interface and factor used in computing
! banded diagonal matrix and set up vector r and vectors a, b, c that define banded
! diagonal matrix and solve system
call ComputeHeatDiffFluxAndFactor(bounds, num_nolakec, filter_nolakec, &
dtime, &
tk( begc:endc, -nlevsno+1: ), &
cv( begc:endc, -nlevsno+1: ), &
fn( begc:endc, -nlevsno+1: ), &
fact( begc:endc, -nlevsno+1: ), &
energyflux_vars, temperature_vars)
! compute thermal properties of h2osfc
do fc = 1,num_nolakec
c = filter_nolakec(fc)
if ( (h2osfc(c) > thin_sfclayer) .and. (frac_h2osfc(c) > thin_sfclayer) ) then
c_h2osfc(c) = max(thin_sfclayer, cpliq*h2osfc(c)/frac_h2osfc(c) )
dz_h2osfc(c) = max(thin_sfclayer, 1.0e-3*h2osfc(c)/frac_h2osfc(c) )
else
c_h2osfc(c) = thin_sfclayer
dz_h2osfc(c) = thin_sfclayer
endif
enddo
! initialize initial temperature vector
tvector_nourbanc(begc:endc, :) = nan
tvector_urbanc( begc:endc, :) = nan
do fc = 1,num_nolakec
c = filter_nolakec(fc)
do j = snl(c)+1, 0
tvector_nourbanc(c,j-1) = t_soisno(c,j)
tvector_urbanc( c,j-1) = t_soisno(c,j)
end do
! surface water layer has two coefficients
tvector_nourbanc(c,0) = t_h2osfc(c)
tvector_urbanc( c,0) = t_h2osfc(c)
! soil layers; top layer will have one offset and one extra coefficient
tvector_nourbanc(c,1:nlevgrnd) = t_soisno(c,1:nlevgrnd)
tvector_urbanc(c,1:nlevgrnd) = t_soisno(c,1:nlevgrnd)
enddo
!
! Solve temperature for non-lake + non-urban columns
!
update_temperature = .true.
select case(thermal_model)
case (default_thermal_model)
urban_column = .false.
call SolveTemperature(bounds, &
num_nolakec_and_nourbanc, &
filter_nolakec_and_nourbanc, &
dtime, &
hs_h2osfc( begc:endc ), &
hs_top_snow( begc:endc ), &
hs_soil( begc:endc ), &
hs_top( begc:endc ), &
dhsdT( begc:endc ), &
sabg_lyr_col (begc:endc, -nlevsno+1: ), &
tk( begc:endc, -nlevsno+1: ), &
tk_h2osfc( begc:endc ), &
fact( begc:endc, -nlevsno+1: ), &
fn( begc:endc, -nlevsno+1: ), &
c_h2osfc( begc:endc ), &
dz_h2osfc( begc:endc ), &
jtop( begc:endc ), &
jbot( begc:endc ), &
temperature_vars, &
waterstate_vars, &
urban_column, &
tvector_nourbanc( begc:endc, -nlevsno: ))
case (petsc_thermal_model)
#ifdef USE_PETSC_LIB
update_temperature = .false.
call Prepare_Data_for_EM_PTM_Driver(bounds, &
num_nolakec_and_nourbanc, &
filter_nolakec_and_nourbanc, &
sabg_lyr_col(begc:endc, -nlevsno+1:), &
dhsdT( begc:endc ), &
hs_soil( begc:endc ), &
hs_top_snow( begc:endc ), &
hs_h2osfc( begc:endc ), &
energyflux_vars &
)
call EMI_Driver(EM_ID_PTM, &
EM_PTM_TBASED_SOLVE_STAGE, &
dt = get_step_size()*1.0_r8, &
clump_rank = bounds%clump_index, &
num_nolakec_and_nourbanc = num_nolakec_and_nourbanc, &
filter_nolakec_and_nourbanc = filter_nolakec_and_nourbanc, &
num_filter_lun = num_filter_lun, &
filter_lun = filter_lun, &
waterstate_vars = waterstate_vars, &
energyflux_vars = energyflux_vars, &
temperature_vars = temperature_vars)
#endif
end select
!
! Solve temperature for lake + urban column
!
urban_column = .true.
call SolveTemperature(bounds, &
num_nolakec_and_urbanc, &
filter_nolakec_and_urbanc, &
dtime, &
hs_h2osfc( begc:endc ), &
hs_top_snow( begc:endc ), &
hs_soil( begc:endc ), &
hs_top( begc:endc ), &
dhsdT( begc:endc ), &
sabg_lyr_col (begc:endc, -nlevsno+1: ), &
tk( begc:endc, -nlevsno+1: ), &
tk_h2osfc( begc:endc ), &
fact( begc:endc, -nlevsno+1: ), &
fn( begc:endc, -nlevsno+1: ), &
c_h2osfc( begc:endc ), &
dz_h2osfc( begc:endc ), &
jtop( begc:endc ), &
jbot( begc:endc ), &
temperature_vars, &
waterstate_vars, &
urban_column, &
tvector_urbanc( begc:endc, -nlevsno: ))
! return temperatures to original array
do fc = 1,num_nolakec
c = filter_nolakec(fc)
l = col_pp%landunit(c)
if (lun_pp%urbpoi(l)) then
do j = snl(c)+1, 0
t_soisno(c,j) = tvector_urbanc(c,j-1) !snow layers
end do
t_soisno(c,1:nlevgrnd) = tvector_urbanc(c,1:nlevgrnd) !soil layers
if (frac_h2osfc(c) == 0._r8) then
t_h2osfc(c) = t_soisno(c,1)
else
t_h2osfc(c) = tvector_urbanc(c,0) !surface water
endif
else
if (update_temperature) then
do j = snl(c)+1, 0
t_soisno(c,j) = tvector_nourbanc(c,j-1) !snow layers
end do
t_soisno(c,1:nlevgrnd) = tvector_nourbanc(c,1:nlevgrnd) !soil layers
if (frac_h2osfc(c) == 0._r8) then
t_h2osfc(c) = t_soisno(c,1)
else
t_h2osfc(c) = tvector_nourbanc(c,0) !surface water
endif
endif
endif
enddo
! Melting or Freezing
do j = -nlevsno+1,nlevgrnd
do fc = 1,num_nolakec
c = filter_nolakec(fc)
l = col_pp%landunit(c)
if ((col_pp%itype(c) == icol_sunwall .or. col_pp%itype(c) == icol_shadewall &
.or. col_pp%itype(c) == icol_roof) .and. j <= nlevurb) then
if (j >= snl(c)+1) then
if (j <= nlevurb-1) then
fn1(c,j) = tk(c,j)*(t_soisno(c,j+1)-t_soisno(c,j))/(z(c,j+1)-z(c,j))
else if (j == nlevurb) then
! For urban sunwall, shadewall, and roof columns, there is a non-zero heat flux across
! the bottom "soil" layer and the equations are derived assuming a prescribed internal
! building temperature. (See Oleson urban notes of 6/18/03).
! Note new formulation for fn, this will be used below in net energey flux computations
fn1(c,j) = tk(c,j) * (t_building(l) - t_soisno(c,j))/(zi(c,j) - z(c,j))
fn(c,j) = tk(c,j) * (t_building(l) - tssbef(c,j))/(zi(c,j) - z(c,j))
end if
end if
else if (col_pp%itype(c) /= icol_sunwall .and. col_pp%itype(c) /= icol_shadewall &
.and. col_pp%itype(c) /= icol_roof) then
if (j >= snl(c)+1) then
if (j <= nlevgrnd-1) then
fn1(c,j) = tk(c,j)*(t_soisno(c,j+1)-t_soisno(c,j))/(z(c,j+1)-z(c,j))
else if (j == nlevgrnd) then
fn1(c,j) = 0._r8
end if
end if
end if
end do
end do
do fc = 1,num_nolakec
c = filter_nolakec(fc)
l = col_pp%landunit(c)
if (lun_pp%urbpoi(l)) then
if (col_pp%itype(c) == icol_sunwall .or. col_pp%itype(c) == icol_shadewall .or. col_pp%itype(c) == icol_roof) then
eflx_building_heat(c) = cnfac*fn(c,nlevurb) + (1._r8-cnfac)*fn1(c,nlevurb)
else
eflx_building_heat(c) = 0._r8
end if
if (cool_on(l)) then
eflx_urban_ac(c) = abs(eflx_building_heat(c))
eflx_urban_heat(c) = 0._r8
else if (heat_on(l)) then
eflx_urban_ac(c) = 0._r8
eflx_urban_heat(c) = abs(eflx_building_heat(c))
else
eflx_urban_ac(c) = 0._r8
eflx_urban_heat(c) = 0._r8
end if
end if
end do
! compute phase change of h2osfc
do fc = 1,num_nolakec
c = filter_nolakec(fc)
xmf_h2osfc(c) = 0.
end do
call PhaseChangeH2osfc (bounds, num_nolakec, filter_nolakec, &
dhsdT(bounds%begc:bounds%endc), &
waterstate_vars, waterflux_vars, temperature_vars, energyflux_vars)
! cnfac = 0.5_r8 ! Crank Nicholson factor between 0 and 1
! Jing Tao added according to Eq. 15 in (Yang&Wang,2018)
do j = -nlevsno+1,nlevgrnd
do fc = 1,num_nolakec
c = filter_nolakec(fc)
fn_mod(c,j) = 0._r8
if(j == snl(c)+1) then
fn_mod(c,j) = cnfac*fn(c,j) + (1.-cnfac)*fn1(c,j)
else
fn_mod(c,j) = cnfac*(fn(c,j)-fn(c,j-1)) + (1.-cnfac)*(fn1(c,j)-fn1(c,j-1))
end if
end do
end do
call Phasechange_beta (bounds, num_nolakec, filter_nolakec, &
dhsdT(bounds%begc:bounds%endc), fn_mod, &
soilstate_vars, waterstate_vars, waterflux_vars, energyflux_vars, temperature_vars)
do fc = 1,num_nolakec
c = filter_nolakec(fc)
! this expression will (should) work whether there is snow or not
if (snl(c) < 0) then
if(frac_h2osfc(c) /= 0._r8) then
t_grnd(c) = frac_sno_eff(c) * t_soisno(c,snl(c)+1) &
+ (1.0_r8 - frac_sno_eff(c) - frac_h2osfc(c)) * t_soisno(c,1) &
+ frac_h2osfc(c) * t_h2osfc(c)
else
t_grnd(c) = frac_sno_eff(c) * t_soisno(c,snl(c)+1) &
+ (1.0_r8 - frac_sno_eff(c)) * t_soisno(c,1)
end if
else
if(frac_h2osfc(c) /= 0._r8) then
t_grnd(c) = (1._r8 - frac_h2osfc(c)) * t_soisno(c,1) + frac_h2osfc(c) * t_h2osfc(c)
else
t_grnd(c) = t_soisno(c,1)
end if
endif
end do
! Initialize soil heat content
do fc = 1,num_nolakec
c = filter_nolakec(fc)
l = col_pp%landunit(c)
if (.not. lun_pp%urbpoi(l)) then
hc_soisno(c) = 0._r8
hc_soi(c) = 0._r8
end if
eflx_fgr12(c)= 0._r8
end do
! Calculate soil heat content and soil plus snow heat content
do j = -nlevsno+1,nlevgrnd
do fc = 1,num_nolakec
c = filter_nolakec(fc)
l = col_pp%landunit(c)
if (j == 1) then ! this only needs to be done once
eflx_fgr12(c) = -cnfac*fn(c,1) - (1._r8-cnfac)*fn1(c,1)
end if
if (j > 0 .and. j < nlevgrnd .and. (lun_pp%itype(l) == istsoil .or. lun_pp%itype(l) == istcrop)) then
eflx_fgr(c,j) = -cnfac*fn(c,j) - (1._r8-cnfac)*fn1(c,j)
else if (j == nlevgrnd .and. (lun_pp%itype(l) == istsoil .or. lun_pp%itype(l) == istcrop)) then
eflx_fgr(c,j) = 0._r8
end if
if (.not. lun_pp%urbpoi(l)) then
if (j >= snl(c)+1) then
hc_soisno(c) = hc_soisno(c) + cv(c,j)*t_soisno(c,j) / 1.e6_r8
endif
if (j >= 1) then
hc_soi(c) = hc_soi(c) + cv(c,j)*t_soisno(c,j) / 1.e6_r8
end if
end if
end do
end do
! Free up memory
deallocate(filter_nolakec_and_nourbanc)
deallocate(filter_nolakec_and_urbanc )
deallocate(filter_lun )
end associate
end subroutine SoilTemperature
!-----------------------------------------------------------------------
subroutine SolveTemperature(bounds, num_filter, filter, dtime, &
hs_h2osfc, hs_top_snow, hs_soil, hs_top, dhsdT, sabg_lyr_col, tk, &
tk_h2osfc, fact, fn, c_h2osfc, dz_h2osfc, jtop, jbot, &
temperature_vars, waterstate_vars, urban_column, tvector)
!
! !DESCRIPTION:
! Assembles and solves the banded penta-diagonal system of equations
!
! !USES:
use clm_varpar , only : nlevsno, nlevgrnd, nlevurb
use clm_varctl , only : iulog
use clm_varcon , only : cnfac, cpice, cpliq, denh2o
use landunit_varcon , only : istice, istice_mec, istsoil, istcrop
use landunit_varcon , only : istwet, istice, istice_mec, istsoil, istcrop
use BandDiagonalMod , only : BandDiagonal
!
! !ARGUMENTS:
implicit none
!
type(bounds_type) , intent(in) :: bounds ! bounds
integer , intent(in) :: num_filter ! number of columns in the filter
integer , intent(in) :: filter(:) ! column filter
real(r8) , intent(in) :: dtime ! land model time step (sec)
real(r8) , intent(in) :: hs_h2osfc( bounds%begc: ) ! heat flux on standing water [W/m2]
real(r8) , intent(in) :: hs_top_snow( bounds%begc: ) ! heat flux on top snow layer [W/m2]
real(r8) , intent(in) :: hs_soil( bounds%begc: ) ! heat flux on soil [W/m2]
real(r8) , intent(in) :: hs_top( bounds%begc: ) ! net energy flux into surface layer (col) [W/m2]
real(r8) , intent(in) :: dhsdT( bounds%begc: ) ! temperature derivative of "hs" [col]
real(r8) , intent(in) :: sabg_lyr_col( bounds%begc: , -nlevsno+1: ) ! absorbed solar radiation (col,lyr) [W/m2]
real(r8) , intent(in) :: tk( bounds%begc: , -nlevsno+1: ) ! thermal conductivity [W/(m K)]
real(r8) , intent(in) :: tk_h2osfc( bounds%begc: ) ! thermal conductivity of h2osfc [W/(m K)] [col]
real(r8) , intent(in) :: fact( bounds%begc: , -nlevsno+1: ) ! used in computing tridiagonal matrix [col, lev]
real(r8) , intent(in) :: fn( bounds%begc: , -nlevsno+1: ) ! heat diffusion through the layer interface [W/m2]
real(r8) , intent(in) :: c_h2osfc( bounds%begc: ) ! heat capacity of surface water [col]
real(r8) , intent(in) :: dz_h2osfc( bounds%begc: ) ! Thickness of standing water [m]
integer , intent(in) :: jtop(bounds%begc: ) ! top level at each column
integer , intent(in) :: jbot(bounds%begc: ) ! bottom level at each column
type(temperature_type) , intent(in) :: temperature_vars !
type(waterstate_type) , intent(in) :: waterstate_vars !
logical , intent(in) :: urban_column ! Is true if solving temperature for urban column, otherwise false
real(r8) , intent(out) :: tvector( bounds%begc: , -nlevsno: ) ! Numerical solution of temperature
!
! !LOCAL VARIABLES:
integer :: c, fc, j
integer, parameter :: nband=5
real(r8) :: bmatrix(bounds%begc:bounds%endc,nband,-nlevsno:nlevgrnd) ! banded matrix for numerical solution of temperature
real(r8) :: rvector(bounds%begc:bounds%endc,-nlevsno:nlevgrnd) ! RHS vector for numerical solution of temperature
!-----------------------------------------------------------------------
associate( &
begc => bounds%begc , &
endc => bounds%endc &
)
! Enforce expected array sizes
SHR_ASSERT_ALL((ubound(hs_h2osfc) == (/bounds%endc/)), errMsg(__FILE__, __LINE__))
SHR_ASSERT_ALL((ubound(hs_top_snow) == (/bounds%endc/)), errMsg(__FILE__, __LINE__))
SHR_ASSERT_ALL((ubound(hs_soil) == (/bounds%endc/)), errMsg(__FILE__, __LINE__))
SHR_ASSERT_ALL((ubound(hs_top) == (/bounds%endc/)), errMsg(__FILE__, __LINE__))
SHR_ASSERT_ALL((ubound(dhsdT) == (/bounds%endc/)), errMsg(__FILE__, __LINE__))
SHR_ASSERT_ALL((ubound(sabg_lyr_col) == (/bounds%endc, 1/)), errMsg(__FILE__, __LINE__))
SHR_ASSERT_ALL((ubound(tk) == (/bounds%endc, nlevgrnd/)), errMsg(__FILE__, __LINE__))
SHR_ASSERT_ALL((ubound(tk_h2osfc) == (/bounds%endc/)), errMsg(__FILE__, __LINE__))
SHR_ASSERT_ALL((ubound(fact) == (/bounds%endc, nlevgrnd/)), errMsg(__FILE__, __LINE__))
SHR_ASSERT_ALL((ubound(fn) == (/bounds%endc, nlevgrnd/)), errMsg(__FILE__, __LINE__))
SHR_ASSERT_ALL((ubound(c_h2osfc) == (/bounds%endc/)), errMsg(__FILE__, __LINE__))
SHR_ASSERT_ALL((ubound(dz_h2osfc) == (/bounds%endc/)), errMsg(__FILE__, __LINE__))
SHR_ASSERT_ALL((ubound(jbot) == (/bounds%endc/)), errMsg(__FILE__, __LINE__))
SHR_ASSERT_ALL((ubound(tvector) == (/bounds%endc, nlevgrnd/)), errMsg(__FILE__, __LINE__))
call SetRHSVec(bounds, num_filter, filter, &
dtime, &
hs_h2osfc( begc:endc ), &
hs_top_snow( begc:endc ), &
hs_soil( begc:endc ), &
hs_top( begc:endc ), &
dhsdT( begc:endc ), &
sabg_lyr_col (begc:endc, -nlevsno+1: ), &
tk( begc:endc, -nlevsno+1: ), &
tk_h2osfc( begc:endc ), &
fact( begc:endc, -nlevsno+1: ), &
fn( begc:endc, -nlevsno+1: ), &
c_h2osfc( begc:endc ), &
dz_h2osfc( begc:endc ), &
temperature_vars, &
waterstate_vars, &
urban_column, &
rvector( begc:endc, -nlevsno: ))
! Set up the banded diagonal matrix
call SetMatrix(bounds, num_filter, filter, &
dtime, &
nband, &
dhsdT( begc:endc ), &
tk( begc:endc, -nlevsno+1: ), &
tk_h2osfc( begc:endc ), &
fact( begc:endc, -nlevsno+1: ), &
c_h2osfc( begc:endc ), &
dz_h2osfc( begc:endc ), &
waterstate_vars, &
urban_column, &
bmatrix( begc:endc, 1:, -nlevsno: ))
! Solve the system
call t_startf( 'SoilTempBandDiag')
call BandDiagonal(bounds, -nlevsno, nlevgrnd, jtop(begc:endc), jbot(begc:endc), &
num_filter, filter, nband, bmatrix(begc:endc, :, :), &
rvector(begc:endc, :), tvector(begc:endc, :))
call t_stopf( 'SoilTempBandDiag')
end associate
end subroutine SolveTemperature
!-----------------------------------------------------------------------
subroutine SoilThermProp (bounds, num_nolakec, filter_nolakec, &
tk, cv, tk_h2osfc, &
urbanparams_vars, temperature_vars, waterstate_vars, soilstate_vars)
!
! !DESCRIPTION:
! Calculation of thermal conductivities and heat capacities of
! snow/soil layers
! (1) The volumetric heat capacity is calculated as a linear combination
! in terms of the volumetric fraction of the constituent phases.
!
! (2) The thermal conductivity of soil is computed from the algorithm of
! Johansen (as reported by Farouki 1981), and of snow is from the
! formulation used in SNTHERM (Jordan 1991).
! The thermal conductivities at the interfaces between two neighboring
! layers (j, j+1) are derived from an assumption that the flux across
! the interface is equal to that from the node j to the interface and the
! flux from the interface to the node j+1.
!
! !USES:
use clm_varpar , only : nlevsno, nlevgrnd, nlevurb, nlevsoi
use clm_varcon , only : denh2o, denice, tfrz, tkwat, tkice, tkair, cpice, cpliq, thk_bedrock
use landunit_varcon , only : istice, istice_mec, istwet
use column_varcon , only : icol_roof, icol_sunwall, icol_shadewall, icol_road_perv, icol_road_imperv
use clm_varctl , only : iulog
!
! !ARGUMENTS:
type(bounds_type) , intent(in) :: bounds
integer , intent(in) :: num_nolakec ! number of column non-lake points in column filter
integer , intent(in) :: filter_nolakec(:) ! column filter for non-lake points
real(r8) , intent(out) :: cv( bounds%begc: , -nlevsno+1: ) ! heat capacity [J/(m2 K) ] [col, lev]
real(r8) , intent(out) :: tk( bounds%begc: , -nlevsno+1: ) ! thermal conductivity at the layer interface [W/(m K) ] [col, lev]
real(r8) , intent(out) :: tk_h2osfc( bounds%begc: ) ! thermal conductivity of h2osfc [W/(m K) ] [col]
type(urbanparams_type) , intent(in) :: urbanparams_vars
type(temperature_type) , intent(in) :: temperature_vars
type(waterstate_type) , intent(inout) :: waterstate_vars
type(soilstate_type) , intent(inout) :: soilstate_vars
!
! !LOCAL VARIABLES:
integer :: l,c,j ! indices
integer :: nlevbed ! # levels to bedrock
integer :: fc ! lake filtered column indices
real(r8) :: dksat ! thermal conductivity for saturated soil (j/(k s m))
real(r8) :: dke ! kersten number
real(r8) :: fl ! volume fraction of liquid or unfrozen water to total water
real(r8) :: satw ! relative total water content of soil.
real(r8) :: zh2osfc
!-----------------------------------------------------------------------
call t_startf( 'SoilThermProp' )
! Enforce expected array sizes
SHR_ASSERT_ALL((ubound(cv) == (/bounds%endc, nlevgrnd/)), errMsg(__FILE__, __LINE__))
SHR_ASSERT_ALL((ubound(tk) == (/bounds%endc, nlevgrnd/)), errMsg(__FILE__, __LINE__))
SHR_ASSERT_ALL((ubound(tk_h2osfc) == (/bounds%endc/)), errMsg(__FILE__, __LINE__))
associate( &
snl => col_pp%snl , & ! Input: [integer (:) ] number of snow layers
dz => col_pp%dz , & ! Input: [real(r8) (:,:) ] layer depth (m)
zi => col_pp%zi , & ! Input: [real(r8) (:,:) ] interface level below a "z" level (m)
z => col_pp%z , & ! Input: [real(r8) (:,:) ] layer thickness (m)
nlev2bed => col_pp%nlevbed , & ! Input: [integer (:) ] number of layers to bedrock
nlev_improad => urbanparams_vars%nlev_improad , & ! Input: [integer (:) ] number of impervious road layers
tk_wall => urbanparams_vars%tk_wall , & ! Input: [real(r8) (:,:) ] thermal conductivity of urban wall
tk_roof => urbanparams_vars%tk_roof , & ! Input: [real(r8) (:,:) ] thermal conductivity of urban roof
tk_improad => urbanparams_vars%tk_improad , & ! Input: [real(r8) (:,:) ] thermal conductivity of urban impervious road
cv_wall => urbanparams_vars%cv_wall , & ! Input: [real(r8) (:,:) ] thermal conductivity of urban wall
cv_roof => urbanparams_vars%cv_roof , & ! Input: [real(r8) (:,:) ] thermal conductivity of urban roof
cv_improad => urbanparams_vars%cv_improad , & ! Input: [real(r8) (:,:) ] thermal conductivity of urban impervious road
t_soisno => col_es%t_soisno , & ! Input: [real(r8) (:,:) ] soil temperature (Kelvin)
frac_sno => col_ws%frac_sno_eff , & ! Input: [real(r8) (:) ] fractional snow covered area
h2osfc => col_ws%h2osfc , & ! Input: [real(r8) (:) ] surface (mm H2O)
h2osno => col_ws%h2osno , & ! Input: [real(r8) (:) ] snow water (mm H2O)
h2osoi_liq => col_ws%h2osoi_liq , & ! Input: [real(r8) (:,:) ] liquid water (kg/m2)
h2osoi_ice => col_ws%h2osoi_ice , & ! Input: [real(r8) (:,:) ] ice lens (kg/m2)
bw => col_ws%bw , & ! Output: [real(r8) (:,:) ] partial density of water in the snow pack (ice + liquid) [kg/m3]
tkmg => soilstate_vars%tkmg_col , & ! Input: [real(r8) (:,:) ] thermal conductivity, soil minerals [W/m-K]
tkdry => soilstate_vars%tkdry_col , & ! Input: [real(r8) (:,:) ] thermal conductivity, dry soil (W/m/Kelvin)
csol => soilstate_vars%csol_col , & ! Input: [real(r8) (:,:) ] heat capacity, soil solids (J/m**3/Kelvin)
watsat => soilstate_vars%watsat_col , & ! Input: [real(r8) (:,:) ] volumetric soil water at saturation (porosity)
tksatu => soilstate_vars%tksatu_col , & ! Input: [real(r8) (:,:) ] thermal conductivity, saturated soil [W/m-K]
thk => soilstate_vars%thk_col & ! Output: [real(r8) (:,:) ] thermal conductivity of each layer [W/m-K]
)
! Thermal conductivity of soil from Farouki (1981)
! Urban values are from Masson et al. 2002, Evaluation of the Town Energy Balance (TEB)
! scheme with direct measurements from dry districts in two cities, J. Appl. Meteorol.,
! 41, 1011-1026.
do j = -nlevsno+1,nlevgrnd
do fc = 1, num_nolakec
c = filter_nolakec(fc)
nlevbed = nlev2bed(c)
! Only examine levels from 1->nlevgrnd
if (j >= 1) then
l = col_pp%landunit(c)
if ((col_pp%itype(c) == icol_sunwall .OR. col_pp%itype(c) == icol_shadewall) .and. j <= nlevurb) then
thk(c,j) = tk_wall(l,j)
else if (col_pp%itype(c) == icol_roof .and. j <= nlevurb) then
thk(c,j) = tk_roof(l,j)
else if (col_pp%itype(c) == icol_road_imperv .and. j >= 1 .and. j <= nlev_improad(l)) then
thk(c,j) = tk_improad(l,j)
else if (lun_pp%itype(l) /= istwet .AND. lun_pp%itype(l) /= istice .AND. lun_pp%itype(l) /= istice_mec &
.AND. col_pp%itype(c) /= icol_sunwall .AND. col_pp%itype(c) /= icol_shadewall .AND. &
col_pp%itype(c) /= icol_roof) then
satw = (h2osoi_liq(c,j)/denh2o + h2osoi_ice(c,j)/denice)/(dz(c,j)*watsat(c,j))
satw = min(1._r8, satw)
if (satw > .1e-6_r8) then
if (t_soisno(c,j) >= tfrz) then ! Unfrozen soil
dke = max(0._r8, log10(satw) + 1.0_r8)
else ! Frozen soil
dke = satw
end if
fl = (h2osoi_liq(c,j)/(denh2o*dz(c,j))) / (h2osoi_liq(c,j)/(denh2o*dz(c,j)) + &
h2osoi_ice(c,j)/(denice*dz(c,j)))
dksat = tkmg(c,j)*tkwat**(fl*watsat(c,j))*tkice**((1._r8-fl)*watsat(c,j))
thk(c,j) = dke*dksat + (1._r8-dke)*tkdry(c,j)
else
thk(c,j) = tkdry(c,j)
endif
if (j > nlevbed) thk(c,j) = thk_bedrock
else if (lun_pp%itype(l) == istice .OR. lun_pp%itype(l) == istice_mec) then
thk(c,j) = tkwat
if (t_soisno(c,j) < tfrz) thk(c,j) = tkice
else if (lun_pp%itype(l) == istwet) then
if (j > nlevbed) then
thk(c,j) = thk_bedrock
else
thk(c,j) = tkwat
if (t_soisno(c,j) < tfrz) thk(c,j) = tkice
endif
endif
endif
! Thermal conductivity of snow, which from Jordan (1991) pp. 18
! Only examine levels from snl(c)+1 -> 0 where snl(c) < 1
if (snl(c)+1 < 1 .AND. (j >= snl(c)+1) .AND. (j <= 0)) then
bw(c,j) = (h2osoi_ice(c,j)+h2osoi_liq(c,j))/(frac_sno(c)*dz(c,j))
thk(c,j) = tkair + (7.75e-5_r8 *bw(c,j) + 1.105e-6_r8*bw(c,j)*bw(c,j))*(tkice-tkair)
end if
end do
end do
! Thermal conductivity at the layer interface
do j = -nlevsno+1,nlevgrnd
do fc = 1,num_nolakec
c = filter_nolakec(fc)
if ((col_pp%itype(c) == icol_sunwall .or. col_pp%itype(c) == icol_shadewall &
.or. col_pp%itype(c) == icol_roof) .and. j <= nlevurb) then
if (j >= snl(c)+1 .AND. j <= nlevurb-1) then
tk(c,j) = thk(c,j)*thk(c,j+1)*(z(c,j+1)-z(c,j)) &