forked from E3SM-Project/E3SM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elm_driver.F90
1903 lines (1589 loc) · 86 KB
/
elm_driver.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 elm_driver
!-----------------------------------------------------------------------
! !DESCRIPTION:
! This module provides the main ELM driver physics calling sequence. Most
! computations occurs over ``clumps'' of gridcells (and associated subgrid
! scale entities) assigned to each MPI process. Computation is further
! parallelized by looping over clumps on each process using shared memory OpenMP.
!
! !USES:
use shr_kind_mod , only : r8 => shr_kind_r8
use shr_sys_mod , only : shr_sys_flush
use shr_log_mod , only : errMsg => shr_log_errMsg
use elm_varpar , only : nlevtrc_soil, nlevsoi
use elm_varctl , only : wrtdia, iulog, create_glacier_mec_landunit, use_fates, use_betr, use_extrasnowlayers
use elm_varctl , only : use_cn, use_lch4, use_voc, use_noio, use_c13, use_c14
use elm_varctl , only : use_erosion, use_fates_sp
use clm_time_manager , only : get_step_size, get_curr_date, get_ref_date, get_nstep, is_beg_curr_day, get_curr_time_string
use clm_time_manager , only : get_curr_calday, get_days_per_year
use elm_varpar , only : nlevsno, nlevgrnd, crop_prog
use spmdMod , only : masterproc, mpicom
use decompMod , only : get_proc_clumps, get_clump_bounds, get_proc_bounds, bounds_type
use filterMod , only : filter, filter_inactive_and_active
use histFileMod , only : hist_update_hbuf, hist_htapes_wrapup
use restFileMod , only : restFile_write, restFile_filename
use abortutils , only : endrun
!
use dynSubgridDriverMod , only : dynSubgrid_driver
use BalanceCheckMod , only : BeginColWaterBalance, ColWaterBalanceCheck
use BalanceCheckMod , only : BeginGridWaterBalance, GridBalanceCheck
!
use CanopyTemperatureMod , only : CanopyTemperature ! (formerly Biogeophysics1Mod)
use SoilTemperatureMod , only : SoilTemperature
use LakeTemperatureMod , only : LakeTemperature
!
use BareGroundFluxesMod , only : BareGroundFluxes
use CanopyFluxesMod , only : CanopyFluxes
use SedYieldMod , only : SoilErosion
use SoilFluxesMod , only : SoilFluxes ! (formerly Biogeophysics2Mod)
use UrbanFluxesMod , only : UrbanFluxes
use LakeFluxesMod , only : LakeFluxes
!
use HydrologyNoDrainageMod , only : HydrologyNoDrainage ! (formerly Hydrology2Mod)
use HydrologyDrainageMod , only : HydrologyDrainage ! (formerly Hydrology2Mod)
use CanopyHydrologyMod , only : CanopyHydrology ! (formerly Hydrology1Mod)
use LakeHydrologyMod , only : LakeHydrology
!
use AerosolMod , only : AerosolMasses
use SnowSnicarMod , only : SnowAge_grain
use SurfaceAlbedoMod , only : SurfaceAlbedo
use UrbanAlbedoMod , only : UrbanAlbedo
!
use SurfaceRadiationMod , only : SurfaceRadiation, CanopySunShadeFractions
use UrbanRadiationMod , only : UrbanRadiation
!
use SedFluxType , only : sedflux_type
!clm_interface
use EcosystemDynMod , only : EcosystemDynNoLeaching1, EcosystemDynNoLeaching2
use EcosystemDynMod , only : EcosystemDynLeaching
use VegStructUpdateMod , only : VegStructUpdate
use AnnualUpdateMod , only : AnnualUpdate
use EcosystemBalanceCheckMod , only : BeginColCBalance, BeginColNBalance, ColCBalanceCheck, ColNBalanceCheck
use EcosystemBalanceCheckMod , only : BeginColPBalance, ColPBalanceCheck
use EcosystemBalanceCheckMod , only : BeginGridCBalance, GridCBalanceCheck
use EcosystemBalanceCheckMod , only : BeginGridNBalance
use EcosystemBalanceCheckMod , only : BeginGridPBalance
use EcosystemBalanceCheckMod , only : EndGridCBalanceAfterDynSubgridDriver
use EcosystemBalanceCheckMod , only : EndGridNBalanceAfterDynSubgridDriver
use EcosystemBalanceCheckMod , only : EndGridPBalanceAfterDynSubgridDriver
use VerticalProfileMod , only : decomp_vertprofiles
use FireMod , only : FireInterp
use SatellitePhenologyMod , only : SatellitePhenology, interpMonthlyVeg
use ndepStreamMod , only : ndep_interp
use pdepStreamMod , only : pdep_interp
use ActiveLayerMod , only : alt_calc
use CH4Mod , only : CH4
use DUSTMod , only : DustDryDep, DustEmission
use VOCEmissionMod , only : VOCEmission
!
use filterMod , only : setFilters
!
use atm2lndMod , only : downscale_forcings
use lnd2atmMod , only : lnd2atm
use lnd2glcMod , only : lnd2glc_type
!
use seq_drydep_mod , only : n_drydep, drydep_method, DD_XLND
use DryDepVelocity , only : depvel_compute
!
use DaylengthMod , only : UpdateDaylength
use perf_mod
!
use elm_instMod , only : ch4_vars, ep_betr
use elm_instMod , only : carbonstate_vars, c13_carbonstate_vars, c14_carbonstate_vars
use elm_instMod , only : carbonflux_vars, c13_carbonflux_vars, c14_carbonflux_vars
use elm_instMod , only : nitrogenstate_vars
use elm_instMod , only : nitrogenflux_vars
use elm_instMod , only : phosphorusstate_vars
use elm_instMod , only : phosphorusflux_vars
use elm_instMod , only : crop_vars
use elm_instMod , only : cnstate_vars
use elm_instMod , only : dust_vars
use elm_instMod , only : vocemis_vars
use elm_instMod , only : drydepvel_vars
use elm_instMod , only : aerosol_vars
use elm_instMod , only : canopystate_vars
use elm_instMod , only : energyflux_vars
use elm_instMod , only : frictionvel_vars
use elm_instMod , only : lakestate_vars
use elm_instMod , only : photosyns_vars
use elm_instMod , only : sedflux_vars
use elm_instMod , only : soilstate_vars
use elm_instMod , only : soilhydrology_vars
use elm_instMod , only : solarabs_vars
use elm_instMod , only : soilhydrology_vars
use elm_instMod , only : surfalb_vars
use elm_instMod , only : surfrad_vars
use elm_instMod , only : temperature_vars
use elm_instMod , only : col_es
use elm_instMod , only : waterflux_vars
use elm_instMod , only : waterstate_vars
use elm_instMod , only : atm2lnd_vars
use elm_instMod , only : lnd2atm_vars
use elm_instMod , only : glc2lnd_vars
use elm_instMod , only : lnd2glc_vars
use elm_instMod , only : soil_water_retention_curve
use elm_instMod , only : chemstate_vars
use elm_instMod , only : alm_fates
use elm_instMod , only : PlantMicKinetics_vars
use tracer_varcon , only : is_active_betr_bgc
use CNEcosystemDynBetrMod , only : CNEcosystemDynBetr, CNFluxStateBetrSummary
use UrbanParamsType , only : urbanparams_vars
use GridcellType , only : grc_pp
use GridcellDataType , only : grc_cs, c13_grc_cs, c14_grc_cs
use GridcellDataType , only : grc_cf, c13_grc_cf, c14_grc_cf
use GridcellDataType , only : grc_ns, grc_nf
use GridcellDataType , only : grc_ps, grc_pf
use TopounitDataType , only : top_as, top_af
use LandunitType , only : lun_pp
use ColumnType , only : col_pp
use ColumnDataType , only : col_es, col_ef, col_ws, col_wf
use ColumnDataType , only : col_cs, c13_col_cs, c14_col_cs
use ColumnDataType , only : col_cf, c13_col_cf, c14_col_cf
use ColumnDataType , only : col_ns, col_nf
use ColumnDataType , only : col_ps, col_pf
use VegetationType , only : veg_pp
use VegetationDataType , only : veg_es, veg_ws, veg_wf, veg_cf
use VegetationDataType , only : veg_cs, c13_veg_cs, c14_veg_cs
use VegetationDataType , only : veg_ns, veg_nf
use VegetationDataType , only : veg_ps, veg_pf
!----------------------------------------------------------------------------
! bgc interface & pflotran:
use elm_varctl , only : use_elm_interface
use elm_instMod , only : elm_interface_data
use elm_interface_funcsMod , only : get_elm_data
! (1) clm_bgc through interface
use elm_varctl , only : use_elm_bgc
use elm_interface_funcsMod , only : elm_bgc_run, update_bgc_data_elm2elm
! (2) pflotran
use clm_time_manager , only : nsstep, nestep
use elm_varctl , only : use_pflotran, pf_cmode, pf_hmode, pf_tmode
use elm_interface_funcsMod , only : update_bgc_data_pf2elm, update_th_data_pf2elm
use elm_interface_pflotranMod , only : elm_pf_run, elm_pf_write_restart
use elm_interface_pflotranMod , only : elm_pf_finalize
!----------------------------------------------------------------------------
use WaterBudgetMod , only : WaterBudget_Reset, WaterBudget_Run, WaterBudget_Accum, WaterBudget_Print
use WaterBudgetMod , only : WaterBudget_SetBeginningMonthlyStates
use WaterBudgetMod , only : WaterBudget_SetEndingMonthlyStates
use CNPBudgetMod , only : CNPBudget_Run, CNPBudget_Accum, CNPBudget_Print, CNPBudget_Reset
use CNPBudgetMod , only : CNPBudget_SetBeginningMonthlyStates, CNPBudget_SetEndingMonthlyStates
use elm_varctl , only : do_budgets, budget_inst, budget_daily, budget_month
use elm_varctl , only : budget_ann, budget_ltann, budget_ltend
use timeinfoMod
!
! !PUBLIC TYPES:
implicit none
!
! !PUBLIC MEMBER FUNCTIONS:
public :: elm_drv ! Main elm driver
!
! !PRIVATE MEMBER FUNCTIONS:
private :: elm_drv_patch2col
private :: elm_drv_init ! Initialization of variables needed from previous timestep
private :: write_diagnostic ! Write diagnostic information to log file
!-----------------------------------------------------------------------
contains
!-----------------------------------------------------------------------
subroutine elm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate)
!
! !DESCRIPTION:
!
! First phase of the clm driver calling the clm physics. An outline of
! the calling tree is given in the description of this module.
!
! !USES:
!
! !ARGUMENTS:
implicit none
logical , intent(in) :: doalb ! true if time for surface albedo calc
real(r8), intent(in) :: nextsw_cday ! calendar day for nstep+1
real(r8), intent(in) :: declinp1 ! declination angle for next time step
real(r8), intent(in) :: declin ! declination angle for current time step
logical, intent(in) :: rstwr ! true => write restart file this step
logical, intent(in) :: nlend ! true => end of run on this step
character(len=*),intent(in) :: rdate ! restart file time stamp for name
!
! !LOCAL VARIABLES:
integer :: nstep ! time step number
real(r8) :: dtime ! land model time step (sec)
integer :: nc, c, p, l, g ! indices
integer :: nclumps ! number of clumps on this processor
integer :: yrp1 ! year (0, ...) for nstep+1
integer :: monp1 ! month (1, ..., 12) for nstep+1
integer :: dayp1 ! day of month (1, ..., 31) for nstep+1
integer :: secp1 ! seconds into current date for nstep+1
integer :: yr ! year (0, ...)
integer :: mon ! month (1, ..., 12)
integer :: day ! day of month (1, ..., 31)
integer :: sec ! seconds of the day
integer :: ncdate ! current date
integer :: nbdate ! base date (reference date)
integer :: kyr ! thousand years, equals 2 at end of first year
character(len=256) :: filer ! restart file name
integer :: ier ! error code
character(len=256) :: dateTimeString
type(bounds_type) :: bounds_clump
type(bounds_type) :: bounds_proc
!-----------------------------------------------------------------------
call get_curr_time_string(dateTimeString)
if (masterproc) then
write(iulog,*)'Beginning timestep : ',trim(dateTimeString)
call shr_sys_flush(iulog)
endif
! Determine processor bounds and clumps for this processor
call get_proc_bounds(bounds_proc)
nclumps = get_proc_clumps()
nstep_mod = get_nstep()
dtime_mod = real(get_step_size(),r8)
call get_curr_date(year_curr,mon_curr, day_curr,secs_curr)
dayspyr_mod = get_days_per_year()
jday_mod = get_curr_calday()
if (do_budgets) then
call WaterBudget_Reset()
if (use_cn) then
call CNPBudget_Reset()
end if
end if
! ============================================================================
! Specified phenology
! ============================================================================
if (use_cn) then
! For dry-deposition need to call CLMSP so that mlaidiff is obtained
if ( n_drydep > 0 .and. drydep_method == DD_XLND ) then
call t_startf('interpMonthlyVeg')
call interpMonthlyVeg(bounds_proc, canopystate_vars)
call t_stopf('interpMonthlyVeg')
endif
elseif(use_fates) then
if(use_fates_sp) then
! For FATES satellite phenology mode interpolate the weights for
! time-interpolation of monthly vegetation data (as in SP mode below)
! Also for FATES with dry-deposition as above need to call CLMSP so that mlaidiff is obtained
!if ( use_fates_sp .or. (n_drydep > 0 .and. drydep_method == DD_XLND ) ) then
! Replace with this when we have dry-deposition working
! For now don't allow for dry-deposition because of issues in #1044 EBK Jun/17/2022
call t_startf('interpMonthlyVeg')
call interpMonthlyVeg(bounds_proc, canopystate_vars)
call t_stopf('interpMonthlyVeg')
end if
else
! Determine weights for time interpolation of monthly vegetation data.
! This also determines whether it is time to read new monthly vegetation and
! obtain updated leaf area index [mlai1,mlai2], stem area index [msai1,msai2],
! vegetation top [mhvt1,mhvt2] and vegetation bottom [mhvb1,mhvb2]. The
! weights obtained here are used in subroutine SatellitePhenology to obtain time
! interpolated values.
if (doalb .or. ( n_drydep > 0 .and. drydep_method == DD_XLND )) then
call t_startf('interpMonthlyVeg')
call interpMonthlyVeg(bounds_proc, canopystate_vars)
call t_stopf('interpMonthlyVeg')
end if
end if
! ==================================================================================
! Determine decomp vertical profiles
!
! These routines (alt_calc & decomp_vertprofiles) need to be called before
! pftdyn_cnbal, and it appears that they need to be called before pftdyn_interp and
! the associated filter updates, too (otherwise we get a carbon balance error)
! ==================================================================================
!$OMP PARALLEL DO PRIVATE (nc,bounds_clump)
do nc = 1,nclumps
call get_clump_bounds(nc, bounds_clump)
call t_startf("decomp_vert")
call alt_calc(filter(nc)%num_soilc, filter(nc)%soilc, &
temperature_vars, canopystate_vars)
! Note (WJS, 6-12-13): Because of this routine's placement in the driver sequence
! (it is called very early in each timestep, before weights are adjusted and
! filters are updated), it may be necessary for this routine to compute values over
! inactive as well as active points (since some inactive points may soon become
! active) - so that's what is done now. Currently, it seems to be okay to do this,
! because the variables computed here seem to only depend on quantities that are
! valid over inactive as well as active points.
if(use_fates .or. use_cn) then
call decomp_vertprofiles(bounds_clump, &
filter_inactive_and_active(nc)%num_soilc, &
filter_inactive_and_active(nc)%soilc, &
filter_inactive_and_active(nc)%num_soilp, &
filter_inactive_and_active(nc)%soilp, &
soilstate_vars, canopystate_vars, cnstate_vars)
end if
call t_stopf("decomp_vert")
end do
!$OMP END PARALLEL DO
! ============================================================================
! Zero fluxes for transient land cover
! ============================================================================
!$OMP PARALLEL DO PRIVATE (nc,bounds_clump)
do nc = 1,nclumps
call get_clump_bounds(nc, bounds_clump)
call t_startf('beggridwbal')
call BeginGridWaterBalance(bounds_clump, &
filter(nc)%num_nolakec, filter(nc)%nolakec, &
filter(nc)%num_lakec, filter(nc)%lakec, &
filter(nc)%num_hydrologyc, filter(nc)%hydrologyc, &
soilhydrology_vars )
call t_stopf('beggridwbal')
if (use_betr) then
dtime=get_step_size(); nstep=get_nstep()
call ep_betr%SetClock(dtime= dtime, nelapstep=nstep)
call ep_betr%BeginMassBalanceCheck(bounds_clump)
endif
call t_startf('cnpinit')
if (use_cn) then
call t_startf('cnpvegzero')
call veg_cs%ZeroDwt(bounds_clump)
if (use_c13) then
call c13_grc_cf%ZeroDWT(bounds_clump)
call c13_col_cf%ZeroDWT(bounds_clump)
end if
if (use_c14) then
call c14_grc_cf%ZeroDWT(bounds_clump)
call c14_col_cf%ZeroDWT(bounds_clump)
end if
call veg_ns%ZeroDWT(bounds_clump)
call veg_ps%ZeroDWT(bounds_clump)
call t_stopf('cnpvegzero')
end if
if (use_cn .or. use_fates) then
call t_startf('cnpzero')
call grc_cf%ZeroDWT(bounds_clump)
call col_cf%ZeroDWT(bounds_clump)
call grc_nf%ZeroDWT(bounds_clump)
call col_nf%ZeroDWT(bounds_clump)
call grc_pf%ZeroDWT(bounds_clump)
call col_pf%ZeroDWT(bounds_clump)
call t_stopf('cnpzero')
end if
call t_startf('cnpvegsumm')
if(use_cn) then
call veg_cs%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
filter(nc)%num_soilp, filter(nc)%soilp, col_cs)
call veg_ns%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
filter(nc)%num_soilp, filter(nc)%soilp, col_ns)
call veg_ps%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
filter(nc)%num_soilp, filter(nc)%soilp, col_ps)
elseif(use_fates)then
! In this scenario, we simply zero all of the
! column level variables that would had been upscaled
! in the veg summary with p2c
call col_cs%ZeroForFates(bounds_clump,filter(nc)%num_soilc, filter(nc)%soilc)
call col_ns%ZeroForFates(bounds_clump,filter(nc)%num_soilc, filter(nc)%soilc)
call col_ps%ZeroForFates(bounds_clump,filter(nc)%num_soilc, filter(nc)%soilc)
end if
call t_stopf('cnpvegsumm')
if(use_cn .or. use_fates)then
call col_cs%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc)
call col_ns%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc)
call col_ps%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc)
call BeginGridCBalance(bounds_clump, col_cs, grc_cs)
call BeginGridNBalance(bounds_clump, col_ns, grc_ns)
call BeginGridPBalance(bounds_clump, col_ps, grc_ps)
end if
call t_stopf('cnpinit')
end do
!$OMP END PARALLEL DO
! ============================================================================
! Update subgrid weights with dynamic landcover (prescribed transient patches,
! and or dynamic landunits), and do related adjustments. Note that this
! call needs to happen outside loops over nclumps.
! ============================================================================
call t_startf('dyn_subgrid')
call dynSubgrid_driver(bounds_proc, &
urbanparams_vars, soilstate_vars, soilhydrology_vars, lakestate_vars, &
energyflux_vars, canopystate_vars, photosyns_vars, cnstate_vars, &
veg_cs, c13_veg_cs, c14_veg_cs, &
col_cs, c13_col_cs, c14_col_cs, col_cf, &
grc_cs, grc_cf , glc2lnd_vars, crop_vars)
call t_stopf('dyn_subgrid')
if (use_cn .or. use_fates) then
nstep = get_nstep()
if (nstep < 2 )then
if (masterproc) then
write(iulog,*) '--WARNING-- skipping CN balance check for first timestep'
end if
else
call t_startf('cnbalchk_at_grid')
!$OMP PARALLEL DO PRIVATE (nc,bounds_clump)
do nc = 1,nclumps
call get_clump_bounds(nc, bounds_clump)
if(use_cn) then
call veg_cs%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
filter(nc)%num_soilp, filter(nc)%soilp, col_cs)
call veg_ns%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
filter(nc)%num_soilp, filter(nc)%soilp, col_ns)
call veg_ps%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
filter(nc)%num_soilp, filter(nc)%soilp, col_ps)
elseif(use_fates)then
! In this scenario, we simply zero all of the
! column level variables that would had been upscaled
! in the veg summary with p2c
call col_cs%ZeroForFates(bounds_clump,filter(nc)%num_soilc, filter(nc)%soilc)
call col_ns%ZeroForFates(bounds_clump,filter(nc)%num_soilc, filter(nc)%soilc)
call col_ps%ZeroForFates(bounds_clump,filter(nc)%num_soilc, filter(nc)%soilc)
end if
call col_cs%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc)
call col_ns%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc)
call col_ps%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc)
call EndGridCBalanceAfterDynSubgridDriver(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
col_cs, grc_cs, grc_cf)
call EndGridNBalanceAfterDynSubgridDriver(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
col_ns, grc_ns, grc_nf)
call EndGridPBalanceAfterDynSubgridDriver(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
col_ps, grc_ps, grc_pf)
end do
!$OMP END PARALLEL DO
call t_stopf('cnbalchk_at_grid')
end if
end if
! ============================================================================
! Initialize the mass balance checks for water.
!
! Currently, I believe this needs to be done after weights are updated for
! prescribed transient patches, because column-level water is not
! generally conserved when weights change (instead the difference is put in
! the grid cell-level terms, qflx_liq_dynbal, etc.). In the future, we may
! want to change the balance checks to ensure that the grid cell-level water
! is conserved, considering qflx_liq_dynbal; in this case, the call to
! BeginWaterBalance should be moved to before the weight updates.
!
! For CNP: This needs to be done after dynSubgrid_driver, because the
! changes due to dynamic area adjustments can break column-level conservation
! ============================================================================
!$OMP PARALLEL DO PRIVATE (nc,bounds_clump)
do nc = 1,nclumps
call get_clump_bounds(nc, bounds_clump)
call t_startf('begwbal')
call BeginColWaterBalance(bounds_clump, &
filter(nc)%num_nolakec, filter(nc)%nolakec, &
filter(nc)%num_lakec, filter(nc)%lakec, &
filter(nc)%num_hydrologyc, filter(nc)%hydrologyc, &
soilhydrology_vars )
call t_stopf('begwbal')
call t_startf('begcnpbal')
! call veg summary before col summary, for p2c
if (use_cn) then
call veg_cs%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
filter(nc)%num_soilp, filter(nc)%soilp, col_cs)
call veg_ns%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
filter(nc)%num_soilp, filter(nc)%soilp, col_ns)
call veg_ps%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
filter(nc)%num_soilp, filter(nc)%soilp, col_ps)
elseif(use_fates)then
! In this scenario, we simply zero all of the
! column level variables that would had been upscaled
! in the veg summary with p2c
call col_cs%ZeroForFates(bounds_clump,filter(nc)%num_soilc, filter(nc)%soilc)
call col_ns%ZeroForFates(bounds_clump,filter(nc)%num_soilc, filter(nc)%soilc)
call col_ps%ZeroForFates(bounds_clump,filter(nc)%num_soilc, filter(nc)%soilc)
end if
call t_stopf('begcnpbal')
if (use_cn .or. use_fates) then
call t_startf('begcnpbalwf')
call col_cs%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc)
call col_ns%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc)
call col_ps%Summary(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc)
call BeginColCBalance(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
col_cs)
call BeginColNBalance(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
col_ns)
call BeginColPBalance(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
col_ps)
call t_stopf('begcnpbalwf')
end if
if (do_budgets) then
call WaterBudget_SetBeginningMonthlyStates(bounds_clump )
if (use_cn) then
call CNPBudget_SetBeginningMonthlyStates(bounds_clump, col_cs, grc_cs)
endif
endif
end do
!$OMP END PARALLEL DO
#ifndef CPL_BYPASS
if (use_cn .or. use_fates) then
! ============================================================================
! Update dynamic N deposition field, on albedo timestep
! currently being done outside clumps loop, but no reason why it couldn't be
! re-written to go inside.
! ============================================================================
call t_startf('ndep_interp')
! PET: switching CN timestep
call ndep_interp(bounds_proc, atm2lnd_vars)
call t_stopf('ndep_interp')
end if
if (use_cn) then
call t_startf('fireinterp')
call FireInterp(bounds_proc)
call t_stopf('fireinterp')
end if
if (use_cn .or. use_fates) then
! ============================================================================
! Update dynamic P deposition field, on albedo timestep
! currently being done outside clumps loop, but no reason why it couldn't be
! re-written to go inside.
! ============================================================================
call t_startf('pdep_interp')
! PET: switching CN timestep
call pdep_interp(bounds_proc, atm2lnd_vars)
call t_stopf('pdep_interp')
end if
#endif
! ============================================================================
! Initialize variables from previous time step, downscale atm forcings, and
! Determine canopy interception and precipitation onto ground surface.
! Determine the fraction of foliage covered by water and the fraction
! of foliage that is dry and transpiring. Initialize snow layer if the
! snow accumulation exceeds 10 mm.
! ============================================================================
!$OMP PARALLEL DO PRIVATE (nc,l,c, bounds_clump)
do nc = 1,nclumps
call get_clump_bounds(nc, bounds_clump)
call t_startf('drvinit')
call UpdateDaylength(bounds_clump, declin)
! Initialze variables needed for new driver time step
call elm_drv_init(bounds_clump, &
filter(nc)%num_nolakec, filter(nc)%nolakec, &
filter(nc)%num_nolakep, filter(nc)%nolakep, &
filter(nc)%num_soilp , filter(nc)%soilp, &
canopystate_vars, energyflux_vars)
call downscale_forcings(bounds_clump, &
filter(nc)%num_do_smb_c, filter(nc)%do_smb_c, &
atm2lnd_vars)
call t_stopf('drvinit')
! ============================================================================
! Canopy Hydrology
! (1) water storage of intercepted precipitation
! (2) direct throughfall and canopy drainage of precipitation
! (3) fraction of foliage covered by water and the fraction is dry and transpiring
! (4) snow layer initialization if the snow accumulation exceeds 10 mm.
! ============================================================================
call t_startf('canhydro')
call CanopyHydrology(bounds_clump, &
filter(nc)%num_nolakec, filter(nc)%nolakec, &
filter(nc)%num_nolakep, filter(nc)%nolakep, &
atm2lnd_vars, canopystate_vars, &
aerosol_vars )
call t_stopf('canhydro')
! ============================================================================
! Surface Radiation
! ============================================================================
call t_startf('surfrad')
! Surface Radiation primarily for non-urban columns
! Most of the surface radiation calculations are agnostic to the forest-model
! but the calculations of the fractions of sunlit and shaded canopies
! are specific, calculate them first.
! The nourbanp filter is set in dySubgrid_driver (earlier in this call)
! over the patch index range defined by bounds_clump%begp:bounds_proc%endp
if(use_fates) then
call alm_fates%wrap_sunfrac(bounds_clump, top_af, canopystate_vars)
else
call CanopySunShadeFractions(filter(nc)%num_nourbanp, filter(nc)%nourbanp, &
atm2lnd_vars, surfalb_vars, canopystate_vars, &
solarabs_vars)
end if
call SurfaceRadiation(bounds_clump, &
filter(nc)%num_nourbanp, filter(nc)%nourbanp, &
filter(nc)%num_urbanp, filter(nc)%urbanp , &
filter(nc)%num_urbanc, filter(nc)%urbanc, &
atm2lnd_vars, canopystate_vars, surfalb_vars, &
solarabs_vars, surfrad_vars)
! Surface Radiation for only urban columns
call UrbanRadiation(bounds_clump, &
filter(nc)%num_nourbanl, filter(nc)%nourbanl, &
filter(nc)%num_urbanl, filter(nc)%urbanl, &
filter(nc)%num_urbanc, filter(nc)%urbanc, &
filter(nc)%num_urbanp, filter(nc)%urbanp, &
atm2lnd_vars, urbanparams_vars, &
solarabs_vars, surfalb_vars, energyflux_vars)
call t_stopf('surfrad')
! ============================================================================
! Determine leaf temperature and surface fluxes based on ground
! temperature from previous time step.
! ============================================================================
call t_startf('bgp1')
call CanopyTemperature(bounds_clump, &
filter(nc)%num_nolakec, filter(nc)%nolakec, &
filter(nc)%num_nolakep, filter(nc)%nolakep, &
atm2lnd_vars, canopystate_vars, soilstate_vars, frictionvel_vars, &
energyflux_vars)
call t_stopf('bgp1')
! ============================================================================
! Determine fluxes
! ============================================================================
call t_startf('bgflux')
call col_wf%Reset(bounds_clump, filter(nc)%num_nolakec , filter(nc)%nolakec)
! Bareground fluxes for all patches except lakes and urban landunits
call BareGroundFluxes(bounds_clump, &
filter(nc)%num_nolakeurbanp, filter(nc)%nolakeurbanp, &
atm2lnd_vars, canopystate_vars, soilstate_vars, &
frictionvel_vars, ch4_vars )
call t_stopf('bgflux')
! non-bareground fluxes for all patches except lakes and urban landunits
! Calculate canopy temperature, latent and sensible fluxes from the canopy,
! and leaf water change by evapotranspiration
call t_startf('canflux')
call CanopyFluxes(bounds_clump, &
filter(nc)%num_nolakeurbanp, filter(nc)%nolakeurbanp, &
atm2lnd_vars, canopystate_vars, cnstate_vars, energyflux_vars, &
frictionvel_vars, soilstate_vars, solarabs_vars, surfalb_vars, &
ch4_vars, photosyns_vars )
call t_stopf('canflux')
! Fluxes for all urban landunits
call t_startf('uflux')
call UrbanFluxes(bounds_clump, &
filter(nc)%num_nourbanl, filter(nc)%nourbanl, &
filter(nc)%num_urbanl, filter(nc)%urbanl, &
filter(nc)%num_urbanc, filter(nc)%urbanc, &
filter(nc)%num_urbanp, filter(nc)%urbanp, &
atm2lnd_vars, urbanparams_vars, soilstate_vars, &
frictionvel_vars, energyflux_vars)
call t_stopf('uflux')
! Fluxes for all lake landunits
call t_startf('bgplake')
call LakeFluxes(bounds_clump, &
filter(nc)%num_lakec, filter(nc)%lakec, &
filter(nc)%num_lakep, filter(nc)%lakep, &
atm2lnd_vars, solarabs_vars, frictionvel_vars, &
energyflux_vars, lakestate_vars)
! ============================================================================
! DUST and VOC emissions
! ============================================================================
call t_startf('bgc')
! Dust mobilization (C. Zender's modified codes)
call DustEmission(bounds_clump, &
filter(nc)%num_nolakep, filter(nc)%nolakep, &
atm2lnd_vars, soilstate_vars, canopystate_vars, &
frictionvel_vars, dust_vars)
! Dust dry deposition (C. Zender's modified codes)
call DustDryDep(bounds_clump, &
atm2lnd_vars, frictionvel_vars, dust_vars)
! VOC emission (A. Guenther's MEGAN (2006) model)
if (use_voc) then
call VOCEmission(bounds_clump, &
filter(nc)%num_soilp, filter(nc)%soilp, &
atm2lnd_vars, canopystate_vars, photosyns_vars, temperature_vars, &
vocemis_vars)
end if
call t_stopf('bgc')
! ============================================================================
! Determine temperatures
! ============================================================================
if(use_betr)then
call ep_betr%BeTRSetBiophysForcing(bounds_clump, col_pp, veg_pp, 1, nlevsoi, waterstate_vars=col_ws)
call ep_betr%PreDiagSoilColWaterFlux(filter(nc)%num_nolakec , filter(nc)%nolakec)
endif
! Set lake temperature
call LakeTemperature(bounds_clump, &
filter(nc)%num_lakec, filter(nc)%lakec, &
filter(nc)%num_lakep, filter(nc)%lakep, &
solarabs_vars, soilstate_vars, ch4_vars, &
energyflux_vars, lakestate_vars)
call t_stopf('bgplake')
! Set soil/snow temperatures including ground temperature
call t_startf('soiltemperature')
call SoilTemperature(bounds_clump, &
filter(nc)%num_urbanl , filter(nc)%urbanl, &
filter(nc)%num_nolakec , filter(nc)%nolakec, &
atm2lnd_vars, urbanparams_vars, canopystate_vars, &
solarabs_vars, soilstate_vars, energyflux_vars )
call t_stopf('soiltemperature')
if(use_betr)then
call ep_betr%BeTRSetBiophysForcing(bounds_clump, col_pp, veg_pp, 1, nlevsoi, waterstate_vars=col_ws)
call ep_betr%DiagnoseDtracerFreezeThaw(bounds_clump, filter(nc)%num_nolakec , filter(nc)%nolakec, col_pp, lun_pp)
endif
! ============================================================================
! update surface fluxes for new ground temperature.
! ============================================================================
call t_startf('bgp2')
call SoilFluxes(bounds_clump, &
filter(nc)%num_urbanl, filter(nc)%urbanl, &
filter(nc)%num_nolakec, filter(nc)%nolakec, &
filter(nc)%num_nolakep, filter(nc)%nolakep, &
atm2lnd_vars, solarabs_vars, canopystate_vars, &
energyflux_vars )
call t_stopf('bgp2')
! ============================================================================
! Perform averaging from patch level to column level
! ============================================================================
call t_startf('patch2col')
call elm_drv_patch2col(bounds_clump, filter(nc)%num_nolakec, filter(nc)%nolakec, energyflux_vars)
call t_stopf('patch2col')
! ============================================================================
! Vertical (column) soil and surface hydrology
! ============================================================================
! Note that filter_snowc and filter_nosnowc are returned by
! LakeHydrology after the new snow filter is built
call t_startf('hydro without drainage')
call HydrologyNoDrainage(bounds_clump, &
filter(nc)%num_nolakec, filter(nc)%nolakec, &
filter(nc)%num_hydrologyc, filter(nc)%hydrologyc, &
filter(nc)%num_hydrononsoic, filter(nc)%hydrononsoic, &
filter(nc)%num_urbanc, filter(nc)%urbanc, &
filter(nc)%num_snowc, filter(nc)%snowc, &
filter(nc)%num_nosnowc, filter(nc)%nosnowc,canopystate_vars, &
atm2lnd_vars, lnd2atm_vars, soilstate_vars, energyflux_vars, &
soilhydrology_vars, aerosol_vars )
! Calculate column-integrated aerosol masses, and
! mass concentrations for radiative calculations and output
! (based on new snow level state, after SnowFilter is rebuilt.
! NEEDS TO BE AFTER SnowFiler is rebuilt, otherwise there
! can be zero snow layers but an active column in filter)
call AerosolMasses( bounds_clump, &
num_on=filter(nc)%num_snowc, filter_on=filter(nc)%snowc, &
num_off=filter(nc)%num_nosnowc, filter_off=filter(nc)%nosnowc, &
aerosol_vars=aerosol_vars)
call t_stopf('hydro without drainage')
! ============================================================================
! Lake hydrology
! ============================================================================
! Note that filter_lakesnowc and filter_lakenosnowc are returned by
! LakeHydrology after the new snow filter is built
call t_startf('hylake')
call LakeHydrology(bounds_clump, &
filter(nc)%num_lakec, filter(nc)%lakec, &
filter(nc)%num_lakep, filter(nc)%lakep, &
filter(nc)%num_lakesnowc, filter(nc)%lakesnowc, &
filter(nc)%num_lakenosnowc, filter(nc)%lakenosnowc, &
atm2lnd_vars, soilstate_vars, &
energyflux_vars, aerosol_vars, lakestate_vars)
! Calculate column-integrated aerosol masses, and
! mass concentrations for radiative calculations and output
! (based on new snow level state, after SnowFilter is rebuilt.
! NEEDS TO BE AFTER SnowFiler is rebuilt, otherwise there
! can be zero snow layers but an active column in filter)
call AerosolMasses(bounds_clump, &
num_on=filter(nc)%num_lakesnowc, filter_on=filter(nc)%lakesnowc, &
num_off=filter(nc)%num_lakenosnowc, filter_off=filter(nc)%lakenosnowc, &
aerosol_vars=aerosol_vars)
! Must be done here because must use a snow filter for lake columns
call SnowAge_grain(bounds_clump, &
filter(nc)%num_lakesnowc, filter(nc)%lakesnowc, &
filter(nc)%num_lakenosnowc, filter(nc)%lakenosnowc )
call t_stopf('hylake')
! ============================================================================
! ! Fraction of soil covered by snow (Z.-L. Yang U. Texas)
! ============================================================================
do c = bounds_clump%begc,bounds_clump%endc
l = col_pp%landunit(c)
if (lun_pp%urbpoi(l)) then
! Urban landunit use Bonan 1996 (LSM Technical Note)
col_ws%frac_sno(c) = min( col_ws%snow_depth(c)/0.05_r8, 1._r8)
end if
end do
! ============================================================================
! Snow aging routine based on Flanner and Zender (2006), Linking snowpack
! microphysics and albedo evolution, JGR, and Brun (1989), Investigation of
! wet-snow metamorphism in respect of liquid-water content, Ann. Glaciol.
! ============================================================================
! Note the snow filters here do not include lakes
! TODO: move this up
call t_startf('snow_init')
call SnowAge_grain(bounds_clump, &
filter(nc)%num_snowc, filter(nc)%snowc, &
filter(nc)%num_nosnowc, filter(nc)%nosnowc )
call t_stopf('snow_init')
! ============================================================================
! Update sediment fluxes from land unit
! ============================================================================
if (use_cn .and. use_erosion) then
call t_startf('erosion')
call SoilErosion(bounds_clump, filter(nc)%num_soilc, filter(nc)%soilc, &
canopystate_vars, cnstate_vars, soilstate_vars, sedflux_vars)
call t_stopf('erosion')
end if
! ============================================================================
! Ecosystem dynamics: Uses CN, or static parameterizations
! ============================================================================
call t_startf('ecosysdyn')
if (use_cn)then
call crop_vars%CropIncrementYear(filter(nc)%num_pcropp, filter(nc)%pcropp)
endif
if(use_betr)then
!right now betr bgc is intended only for non-ed mode
if(is_active_betr_bgc)then
!this returns the plant nutrient demand to soil bgc
call CNEcosystemDynBetr(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
filter(nc)%num_soilp, filter(nc)%soilp, &
filter(nc)%num_pcropp, filter(nc)%pcropp, doalb, &
cnstate_vars, carbonflux_vars, carbonstate_vars, &
c13_carbonflux_vars, c13_carbonstate_vars, &
c14_carbonflux_vars, c14_carbonstate_vars, &
nitrogenflux_vars, nitrogenstate_vars, &
atm2lnd_vars, waterstate_vars, waterflux_vars, &
canopystate_vars, soilstate_vars, temperature_vars, crop_vars, &
photosyns_vars, soilhydrology_vars, energyflux_vars,&
PlantMicKinetics_vars, &
phosphorusflux_vars, phosphorusstate_vars)
call AnnualUpdate(bounds_clump, &
filter(nc)%num_soilc, filter(nc)%soilc, &
filter(nc)%num_soilp, filter(nc)%soilp, &
cnstate_vars)
endif
endif