-
Notifications
You must be signed in to change notification settings - Fork 321
/
Copy pathclmfates_interfaceMod.F90
3989 lines (3123 loc) · 170 KB
/
clmfates_interfaceMod.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 CLMFatesInterfaceMod
! -------------------------------------------------------------------------------------
! This module contains various functions and definitions to aid in the
! coupling of the FATES library/API with the CLM/ALM/ATS/etc model driver.
! All connections between the two models should occur in this file alone.
!
! This is also the only location where CLM code is allowed to see FATES memory
! structures.
! The routines here, that call FATES library routines, cannot pass most types defined
! by the driving land model (HLM), only native type arrays (int,real,log, etc), implementations
! of fates abstract classes, and references into fates boundary condition structures.
!
! Note that CLM/ALM does use Shared Memory Parallelism (SMP), where processes such as
! the update of state variables are forked. However, IO is not assumed to be
! threadsafe and therefore memory spaces reserved for IO must be continuous vectors,
! and moreover they must be pushed/pulled from history IO for each individual
! bounds_proc memory space as a unit.
!
! Therefore, the state variables in the clm_fates communicator is vectorized by
! threadcount, and the IO communication arrays are not.
!
!
! Conventions:
! keep line widths within 90 spaces
! HLM acronym = Host Land Model
!
! -------------------------------------------------------------------------------------
! use ed_driver_interface, only:
! Used CLM Modules
#include "shr_assert.h"
use PatchType , only : patch
use shr_kind_mod , only : r8 => shr_kind_r8
use decompMod , only : bounds_type, subgrid_level_column
use WaterStateBulkType , only : waterstatebulk_type
use WaterDiagnosticBulkType , only : waterdiagnosticbulk_type
use WaterFluxBulkType , only : waterfluxbulk_type
use Wateratm2lndBulkType , only : wateratm2lndbulk_type
use ActiveLayerMod , only : active_layer_type
use CanopyStateType , only : canopystate_type
use TemperatureType , only : temperature_type
use EnergyFluxType , only : energyflux_type
use SoilStateType , only : soilstate_type
use CNProductsMod , only : cn_products_type
use clm_varctl , only : iulog
use clm_varctl , only : fates_parteh_mode
use PRTGenericMod , only : prt_cnp_flex_allom_hyp
use clm_varctl , only : use_fates
use clm_varctl , only : fates_spitfire_mode
use clm_varctl , only : use_fates_tree_damage
use clm_varctl , only : use_fates_planthydro
use clm_varctl , only : use_fates_cohort_age_tracking
use clm_varctl , only : use_fates_daylength_factor
use clm_varctl , only : fates_photosynth_acclimation
use clm_varctl , only : use_fates_ed_st3
use clm_varctl , only : use_fates_ed_prescribed_phys
use clm_varctl , only : fates_harvest_mode
use clm_varctl , only : fates_stomatal_model
use clm_varctl , only : fates_stomatal_assimilation
use clm_varctl , only : fates_leafresp_model
use clm_varctl , only : fates_cstarvation_model
use clm_varctl , only : fates_regeneration_model
use clm_varctl , only : fates_hydro_solver
use clm_varctl , only : fates_radiation_model
use clm_varctl , only : fates_electron_transport_model
use clm_varctl , only : use_fates_inventory_init
use clm_varctl , only : use_fates_fixed_biogeog
use clm_varctl , only : use_fates_nocomp
use clm_varctl , only : use_fates_sp
use clm_varctl , only : use_fates_luh
use clm_varctl , only : use_fates_lupft
use clm_varctl , only : use_fates_potentialveg
use clm_varctl , only : flandusepftdat
use clm_varctl , only : fates_seeddisp_cadence
use clm_varctl , only : fates_inventory_ctrl_filename
use clm_varctl , only : use_nitrif_denitrif
use clm_varctl , only : use_lch4
use clm_varctl , only : fates_history_dimlevel
use clm_varctl , only : nsrest, nsrBranch
use clm_varcon , only : tfrz
use clm_varcon , only : spval
use clm_varcon , only : denice
use clm_varcon , only : ispval
use clm_varcon , only : sum_to_1_tol
use clm_varpar , only : surfpft_lb,surfpft_ub
use clm_varpar , only : numrad
use clm_varpar , only : ivis
use clm_varpar , only : inir
use clm_varpar , only : nlevdecomp
use clm_varpar , only : nlevdecomp_full
use clm_varpar , only : nlevsoi
use PhotosynthesisMod , only : photosyns_type
use atm2lndType , only : atm2lnd_type
use SurfaceAlbedoType , only : surfalb_type
use SolarAbsorbedType , only : solarabs_type
use SoilBiogeochemCarbonFluxType, only : soilbiogeochem_carbonflux_type
use SoilBiogeochemCarbonStateType, only : soilbiogeochem_carbonstate_type
use SoilBiogeochemNitrogenFluxType, only : soilbiogeochem_nitrogenflux_type
use SoilBiogeochemNitrogenStateType, only : soilbiogeochem_nitrogenstate_type
use FrictionVelocityMod , only : frictionvel_type
use clm_time_manager , only : is_restart, is_first_restart_step
use ncdio_pio , only : file_desc_t, ncd_int, ncd_double
use restUtilMod, only : restartvar
use clm_time_manager , only : get_curr_days_per_year, &
get_curr_date, &
get_ref_date, &
timemgr_datediff, &
is_beg_curr_day, &
get_step_size_real,&
get_nstep
use spmdMod , only : masterproc
use decompMod , only : get_proc_bounds, &
get_proc_clumps, &
get_proc_global, &
get_clump_bounds
use SoilBiogeochemDecompCascadeConType , only : mimics_decomp, decomp_method
use SoilBiogeochemDecompCascadeConType , only : no_soil_decomp, century_decomp
use SoilWaterRetentionCurveMod, only : soil_water_retention_curve_type
use GridCellType , only : grc
use ColumnType , only : col
use LandunitType , only : lun
use landunit_varcon , only : istsoil
use abortutils , only : endrun
use shr_log_mod , only : errMsg => shr_log_errMsg
use clm_varcon , only : dzsoi_decomp
use FuncPedotransferMod, only: get_ipedof
use CLMFatesParamInterfaceMod, only: fates_param_reader_ctsm_impl
! use SoilWaterPlantSinkMod, only : Compute_EffecRootFrac_And_VertTranSink_Default
! Used FATES Modules
use FatesInterfaceMod , only : fates_interface_type
use FatesInterfaceMod, only : FatesInterfaceInit, FatesReportParameters
use FatesInterfaceMod, only : SetFatesGlobalElements1
use FatesInterfaceMod, only : SetFatesGlobalElements2
use FatesInterfaceMod , only : allocate_bcin
use FatesInterfaceMod , only : allocate_bcout
use FatesInterfaceMod , only : allocate_bcpconst
use FatesInterfaceMod , only : set_bcpconst
use FatesInterfaceMod , only : zero_bcs
use FatesInterfaceMod , only : SetFatesTime
use FatesInterfaceMod , only : set_fates_ctrlparms
use FatesInterfaceMod , only : UpdateFatesRMeansTStep
use FatesInterfaceMod , only : InitTimeAveragingGlobals
use FatesParametersInterface, only : fates_param_reader_type
use FatesParametersInterface, only : fates_parameters_type
use FatesInterfaceMod , only : DetermineGridCellNeighbors
use FatesHistoryInterfaceMod, only : fates_hist
use FatesRestartInterfaceMod, only : fates_restart_interface_type
use FatesPatchMod , only : fates_patch_type
use PRTGenericMod , only : num_elements
use FatesInterfaceTypesMod, only : hlm_stepsize
use FatesInterfaceTypesMod, only : fates_maxPatchesPerSite
use FatesInterfaceTypesMod, only : hlm_num_luh2_states
use FatesInterfaceTypesMod, only : fates_dispersal_cadence_none
use EDMainMod , only : ed_ecosystem_dynamics
use EDMainMod , only : ed_update_site
use EDInitMod , only : zero_site
use EDInitMod , only : init_site_vars
use EDInitMod , only : init_patches
use EDInitMod , only : set_site_properties
use EDPftVarcon , only : EDpftvarcon_inst
use FatesRadiationDriveMod, only : FatesSunShadeFracs, FatesNormalizedCanopyRadiation
use EDBtranMod , only : btran_ed, &
get_active_suction_layers
use EDCanopyStructureMod , only : canopy_summarization, update_hlm_dynamics
use EDCanopyStructureMod , only : UpdateFatesAvgSnowDepth
use FatesPlantRespPhotosynthMod, only : FatesPlantRespPhotosynthDrive
use EDAccumulateFluxesMod , only : AccumulateFluxes_ED
use FatesSoilBGCFluxMod , only : FluxIntoLitterPools
use FatesSoilBGCFluxMod , only : UnPackNutrientAquisitionBCs
use FatesPlantHydraulicsMod, only : hydraulics_drive
use FatesPlantHydraulicsMod, only : HydrSiteColdStart
use FatesPlantHydraulicsMod, only : InitHydrSites
use FatesPlantHydraulicsMod, only : RestartHydrStates
use FATESFireBase , only : fates_fire_base_type
use FATESFireFactoryMod , only : no_fire, scalar_lightning, successful_ignitions,&
anthro_ignitions, anthro_suppression
use dynHarvestMod , only : num_harvest_inst, harvest_varnames
use dynHarvestMod , only : harvest_units, mass_units, unitless_units
use dynHarvestMod , only : dynHarvest_interp_resolve_harvesttypes
use FatesConstantsMod , only : hlm_harvest_area_fraction
use FatesConstantsMod , only : hlm_harvest_carbon
use FatesDispersalMod , only : lneighbors, dispersal_type, IsItDispersalTime
use perf_mod , only : t_startf, t_stopf
use dynFATESLandUseChangeMod, only : num_landuse_transition_vars, num_landuse_state_vars
use dynFATESLandUseChangeMod, only : landuse_transitions, landuse_states
use dynFATESLandUseChangeMod, only : landuse_transition_varnames, landuse_state_varnames
use dynFATESLandUseChangeMod, only : num_landuse_harvest_vars
use dynFATESLandUseChangeMod, only : fates_harvest_no_logging
use dynFATESLandUseChangeMod, only : fates_harvest_clmlanduse
use dynFATESLandUseChangeMod, only : fates_harvest_luh_area
use dynFATESLandUseChangeMod, only : fates_harvest_luh_mass
use dynFATESLandUseChangeMod, only : landuse_harvest
use dynFATESLandUseChangeMod, only : landuse_harvest_units
use dynFATESLandUseChangeMod, only : landuse_harvest_varnames
implicit none
type, public :: f2hmap_type
! This is the associated column index of each FATES site
integer, allocatable :: fcolumn (:)
! This is the associated site index of any HLM columns
! This vector may be sparse, and non-sites have index 0
integer, allocatable :: hsites (:)
end type f2hmap_type
type, public :: hlm_fates_interface_type
! private
! See above for descriptions of the sub-types populated
! by thread. This type is somewhat self-explanatory, in that it simply
! breaks up memory and process by thread. Each thread will have its
! own list of sites, and boundary conditions for those sites
type(fates_interface_type), allocatable :: fates (:)
! This memory structure is used to map fates sites
! into the host model. Currently, the FATES site
! and its column number matching are its only members
type(f2hmap_type), allocatable :: f2hmap(:)
! fates_restart is the inteface calss for restarting the model
type(fates_restart_interface_type) :: fates_restart
! fates_fire_data_method determines the fire data passed from HLM to FATES
class(fates_fire_base_type), allocatable :: fates_fire_data_method
! Type structure that holds allocatable arrays for mpi-based seed dispersal
type(dispersal_type) :: fates_seed
contains
procedure, public :: init
procedure, public :: check_hlm_active
procedure, public :: restart
procedure, public :: init_coldstart
procedure, public :: dynamics_driv
procedure, public :: wrap_sunfrac
procedure, public :: wrap_btran
procedure, public :: wrap_photosynthesis
procedure, public :: wrap_accumulatefluxes
procedure, public :: prep_canopyfluxes
procedure, public :: wrap_canopy_radiation
procedure, public :: wrap_update_hifrq_hist
procedure, public :: TransferZ0mDisp
procedure, public :: InterpFileInputs ! Interpolate inputs from files
procedure, public :: Init2 ! Initialization after determining subgrid weights
procedure, public :: InitAccBuffer ! Initialize any accumulation buffers
procedure, public :: InitAccVars ! Initialize any accumulation variables
procedure, public :: UpdateAccVars ! Update any accumulation variables
procedure, private :: init_history_io
procedure, private :: wrap_update_hlmfates_dyn
procedure, private :: init_soil_depths
procedure, public :: ComputeRootSoilFlux
procedure, public :: wrap_hydraulics_drive
procedure, public :: WrapUpdateFatesRmean
procedure, public :: wrap_WoodProducts
procedure, public :: WrapGlobalSeedDispersal
procedure, public :: WrapUpdateFatesSeedInOut
procedure, public :: UpdateCLitterFluxes
procedure, public :: UpdateNLitterFluxes
end type hlm_fates_interface_type
! hlm_bounds_to_fates_bounds is not currently called outside the interface.
! Although there may be good reasons to, I privatized it so that the next
! developer will at least question its usage (RGK)
private :: hlm_bounds_to_fates_bounds
! The GetAndSetTime function is used to get the current time from the CLM
! time procedures and then set to the fates global time variables during restart,
! init_coldstart, and dynamics_driv function calls
private :: GetAndSetTime
logical :: debug = .false.
logical, private, allocatable :: copy_fates_var(:) ! .true. -> copy variable from FATES to CTSM in clmfates_interface
! .false. -> do not copy in clmfates_interface and use value already in memory
character(len=*), parameter, private :: sourcefile = &
__FILE__
integer, parameter :: num_landuse_pft_vars = 4
public :: CLMFatesGlobals1
public :: CLMFatesGlobals2
public :: CrossRefHistoryFields
contains
subroutine CLMFatesGlobals1(surf_numpft,surf_numcft,maxsoil_patches)
! --------------------------------------------------------------------------------
! This is the first call to fates
! We open the fates parameter file. And use that and some info on
! namelist variables to determine how many patches need to be allocated
! in CTSM
! --------------------------------------------------------------------------------
integer,intent(in) :: surf_numpft
integer,intent(in) :: surf_numcft
integer,intent(out) :: maxsoil_patches
integer :: pass_use_fixed_biogeog
integer :: pass_use_nocomp
integer :: pass_use_sp
integer :: pass_masterproc
integer :: pass_use_luh2
logical :: verbose_output
type(fates_param_reader_ctsm_impl) :: var_reader
call t_startf('fates_globals1')
if (use_fates) then
verbose_output = .false.
call FatesInterfaceInit(iulog, verbose_output)
! Force FATES parameters that are recieve type, to the unset value
call set_fates_ctrlparms('flush_to_unset')
! Send parameters individually
if(use_fates_fixed_biogeog)then
pass_use_fixed_biogeog = 1
else
pass_use_fixed_biogeog = 0
end if
call set_fates_ctrlparms('use_fixed_biogeog',ival=pass_use_fixed_biogeog)
if(use_fates_nocomp)then
pass_use_nocomp = 1
else
pass_use_nocomp = 0
end if
call set_fates_ctrlparms('use_nocomp',ival=pass_use_nocomp)
if(use_fates_sp)then
pass_use_sp = 1
else
pass_use_sp = 0
end if
call set_fates_ctrlparms('use_sp',ival=pass_use_sp)
if(masterproc)then
pass_masterproc = 1
else
pass_masterproc = 0
end if
call set_fates_ctrlparms('masterproc',ival=pass_masterproc)
! FATES landuse modes
if(use_fates_luh) then
pass_use_luh2 = 1
else
pass_use_luh2 = 0
end if
call set_fates_ctrlparms('use_luh2',ival=pass_use_luh2)
end if
! The following call reads in the parameter file
! and then uses that to determine the number of patches
! FATES requires. We pass that to CLM here
! so that it can perform some of its allocations.
! During init 2, we will perform more size checks
! and allocations on the FATES side, which require
! some allocations from CLM (like soil layering)
call SetFatesGlobalElements1(use_fates,surf_numpft,surf_numcft,var_reader)
maxsoil_patches = fates_maxPatchesPerSite
call t_stopf('fates_globals1')
return
end subroutine CLMFatesGlobals1
! ===================================================================================
subroutine CLMFatesGlobals2()
! --------------------------------------------------------------------------------
! This is one of the first calls to fates
! Used for setting dimensions. This MUST
! be called after NL variables are specified and
! after the FATES parameter file has been read in
! Aside from setting global dimension info, which
! is used in the history file, we also transfer
! over the NL variables to FATES global settings.
! --------------------------------------------------------------------------------
integer :: pass_vertsoilc
integer :: pass_ch4
integer :: pass_spitfire
integer :: pass_ed_st3
integer :: pass_num_lu_harvest_cats
integer :: pass_lu_harvest
integer :: pass_logging
integer :: pass_ed_prescribed_phys
integer :: pass_planthydro
integer :: pass_inventory_init
integer :: pass_is_restart
integer :: pass_cohort_age_tracking
integer :: pass_tree_damage
integer :: pass_use_potentialveg
integer :: pass_num_luh_states
integer :: pass_num_luh_transitions
integer :: pass_photosynth_acclimation_switch
integer :: pass_daylength_factor_switch
integer :: pass_stomatal_model
integer :: pass_stomatal_assimilation
integer :: pass_leafresp_model
integer :: pass_cstarvation_model
integer :: pass_regeneration_model
integer :: pass_hydro_solver
integer :: pass_radiation_model
integer :: pass_electron_transport_model
call t_startf('fates_globals2')
if (use_fates) then
! Send parameters individually
call set_fates_ctrlparms('num_sw_bbands',ival=numrad)
call set_fates_ctrlparms('vis_sw_index',ival=ivis)
call set_fates_ctrlparms('nir_sw_index',ival=inir)
call set_fates_ctrlparms('num_lev_soil',ival=nlevsoi)
call set_fates_ctrlparms('hlm_name',cval='CLM')
call set_fates_ctrlparms('hio_ignore_val',rval=spval)
call set_fates_ctrlparms('soilwater_ipedof',ival=get_ipedof(0))
call set_fates_ctrlparms('parteh_mode',ival=fates_parteh_mode)
call set_fates_ctrlparms('seeddisp_cadence',ival=fates_seeddisp_cadence)
call set_fates_ctrlparms('hist_hifrq_dimlevel',ival=fates_history_dimlevel(1))
call set_fates_ctrlparms('hist_dynam_dimlevel',ival=fates_history_dimlevel(2))
! CTSM-FATES is not fully coupled (yet)
! So lets tell fates to use the RD competition mechanism
! which has fewer boundary conditions (simpler)
call set_fates_ctrlparms('nu_com',cval='RD')
if (decomp_method == mimics_decomp) then
call set_fates_ctrlparms('decomp_method',cval='MIMICS')
elseif(decomp_method == century_decomp ) then
call set_fates_ctrlparms('decomp_method',cval='CENTURY')
elseif(decomp_method == no_soil_decomp ) then
call set_fates_ctrlparms('decomp_method',cval='NONE')
end if
if(use_fates_tree_damage)then
pass_tree_damage = 1
else
pass_tree_damage = 0
end if
call set_fates_ctrlparms('use_tree_damage',ival=pass_tree_damage)
! These may be in a non-limiting status (ie when supplements)
! are added, but they are always allocated and cycled non-the less
! FATES may want to interact differently with other models
! that don't even have these arrays allocated.
! FATES also checks that if NO3 is cycled in ELM, then
! any plant affinity parameters are checked.
if(use_nitrif_denitrif) then
call set_fates_ctrlparms('nitrogen_spec',ival=1)
else
call set_fates_ctrlparms('nitrogen_spec',ival=2)
end if
! Phosphorus is not tracked in CLM
call set_fates_ctrlparms('phosphorus_spec',ival=0)
call set_fates_ctrlparms('spitfire_mode',ival=fates_spitfire_mode)
call set_fates_ctrlparms('sf_nofire_def',ival=no_fire)
call set_fates_ctrlparms('sf_scalar_lightning_def',ival=scalar_lightning)
call set_fates_ctrlparms('sf_successful_ignitions_def',ival=successful_ignitions)
call set_fates_ctrlparms('sf_anthro_ignitions_def',ival=anthro_ignitions)
! This has no variable on the FATES side yet (RGK)
!call set_fates_ctrlparms('sf_anthro_suppression_def',ival=anthro_suppression)
if(is_restart() .or. nsrest .eq. nsrBranch) then
pass_is_restart = 1
else
pass_is_restart = 0
end if
call set_fates_ctrlparms('is_restart',ival=pass_is_restart)
if(use_lch4) then
pass_ch4 = 1
else
pass_ch4 = 0
end if
call set_fates_ctrlparms('use_ch4',ival=pass_ch4)
! use_vertsoilc: Carbon soil layer profile is assumed to be on all the time now
pass_vertsoilc = 1
call set_fates_ctrlparms('use_vertsoilc',ival=pass_vertsoilc)
if(use_fates_ed_st3) then
pass_ed_st3 = 1
else
pass_ed_st3 = 0
end if
call set_fates_ctrlparms('use_ed_st3',ival=pass_ed_st3)
if(use_fates_ed_prescribed_phys) then
pass_ed_prescribed_phys = 1
else
pass_ed_prescribed_phys = 0
end if
call set_fates_ctrlparms('use_ed_prescribed_phys',ival=pass_ed_prescribed_phys)
if(use_fates_planthydro) then
pass_planthydro = 1
else
pass_planthydro = 0
end if
call set_fates_ctrlparms('use_planthydro',ival=pass_planthydro)
if(use_fates_cohort_age_tracking) then
pass_cohort_age_tracking = 1
else
pass_cohort_age_tracking = 0
end if
call set_fates_ctrlparms('use_cohort_age_tracking',ival=pass_cohort_age_tracking)
if(trim(fates_photosynth_acclimation) == 'kumarathunge2019') then
pass_photosynth_acclimation_switch = 1
else if(trim(fates_photosynth_acclimation) == 'nonacclimating') then
pass_photosynth_acclimation_switch = 0
end if
call set_fates_ctrlparms('photosynth_acclimation',ival=pass_photosynth_acclimation_switch)
if(use_fates_daylength_factor) then
pass_daylength_factor_switch = 1
else
pass_daylength_factor_switch = 0
end if
call set_fates_ctrlparms('use_daylength_factor_switch',ival=pass_daylength_factor_switch)
if (trim(fates_stomatal_model) == 'ballberry1987') then
pass_stomatal_model = 1
else if (trim(fates_stomatal_model) == 'medlyn2011') then
pass_stomatal_model = 2
end if
call set_fates_ctrlparms('stomatal_model',ival=pass_stomatal_model)
if (trim(fates_stomatal_assimilation) == 'net') then
pass_stomatal_assimilation = 1
else if (trim(fates_stomatal_assimilation) == 'gross') then
pass_stomatal_assimilation = 2
end if
call set_fates_ctrlparms('stomatal_assim_model',ival=pass_stomatal_assimilation)
if (trim(fates_leafresp_model) == 'ryan1991') then
pass_leafresp_model = 1
else if (trim(fates_leafresp_model) == 'atkin2017') then
pass_leafresp_model = 2
end if
call set_fates_ctrlparms('maintresp_leaf_model',ival=pass_leafresp_model)
if (trim(fates_cstarvation_model) == 'linear') then
pass_cstarvation_model = 1
else if (trim(fates_cstarvation_model) == 'expontential') then
pass_cstarvation_model = 2
end if
call set_fates_ctrlparms('mort_cstarvation_model',ival=pass_cstarvation_model)
if (trim(fates_regeneration_model) == 'default') then
pass_regeneration_model = 1
else if (trim(fates_regeneration_model) == 'trs') then
pass_regeneration_model = 2
else if (trim(fates_regeneration_model) == 'trs_no_seed_dyn') then
pass_regeneration_model = 3
end if
call set_fates_ctrlparms('regeneration_model',ival=pass_regeneration_model)
if (trim(fates_hydro_solver) == '1D_Taylor') then
pass_hydro_solver = 1
else if (trim(fates_hydro_solver) == '2D_Picard') then
pass_hydro_solver = 2
else if (trim(fates_hydro_solver) == '2D_Newton') then
pass_hydro_solver = 3
end if
call set_fates_ctrlparms('hydr_solver',ival=pass_hydro_solver)
if (trim(fates_radiation_model) == 'norman') then
pass_radiation_model = 1
else if (trim(fates_radiation_model) == 'twostream') then
pass_radiation_model = 2
end if
call set_fates_ctrlparms('radiation_model',ival=pass_radiation_model)
if (trim(fates_electron_transport_model) == 'FvCB1980') then
pass_radiation_model = 1
else if (trim(fates_electron_transport_model) == 'JohnsonBerry2021') then
pass_radiation_model = 2
end if
call set_fates_ctrlparms('electron_transport_model',ival=pass_electron_transport_model)
! FATES logging and harvest modes
pass_logging = 0
pass_lu_harvest = 0
pass_num_lu_harvest_cats = 0
if (trim(fates_harvest_mode) /= fates_harvest_no_logging) then
pass_logging = 1 ! Time driven logging, without landuse harvest
! CLM landuse timeseries driven harvest rates
if (trim(fates_harvest_mode) == fates_harvest_clmlanduse) then
pass_num_lu_harvest_cats = num_harvest_inst
pass_lu_harvest = 1
! LUH2 landuse timeseries driven harvest rates
else if (trim(fates_harvest_mode)== fates_harvest_luh_area .or. &
trim(fates_harvest_mode)== fates_harvest_luh_mass) then
pass_lu_harvest = 1
pass_num_lu_harvest_cats = num_landuse_harvest_vars
end if
end if
call set_fates_ctrlparms('use_lu_harvest',ival=pass_lu_harvest)
call set_fates_ctrlparms('num_lu_harvest_cats',ival=pass_num_lu_harvest_cats)
call set_fates_ctrlparms('use_logging',ival=pass_logging)
! FATES landuse modes
if(use_fates_luh) then
pass_num_luh_states = num_landuse_state_vars
pass_num_luh_transitions = num_landuse_transition_vars
else
pass_num_luh_states = 0
pass_num_luh_transitions = 0
end if
call set_fates_ctrlparms('num_luh2_states',ival=pass_num_luh_states)
call set_fates_ctrlparms('num_luh2_transitions',ival=pass_num_luh_transitions)
if ( use_fates_potentialveg ) then
pass_use_potentialveg = 1
else
pass_use_potentialveg = 0
end if
call set_fates_ctrlparms('use_fates_potentialveg',ival=pass_use_potentialveg)
if(use_fates_inventory_init) then
pass_inventory_init = 1
else
pass_inventory_init = 0
end if
call set_fates_ctrlparms('use_inventory_init',ival=pass_inventory_init)
call set_fates_ctrlparms('inventory_ctrl_file',cval=fates_inventory_ctrl_filename)
! Check through FATES parameters to see if all have been set
call set_fates_ctrlparms('check_allset')
end if
! This determines the total amount of space it requires in its largest
! dimension. We are currently calling that the "cohort" dimension, but
! it is really a utility dimension that captures the models largest
! size need.
! Sets:
! fates_maxElementsPerPatch
! num_elements
! fates_maxElementsPerSite (where a site is roughly equivalent to a column)
! (Note: this needs to be called when use_fates=.false. as well, becuase
! it will return some nominal dimension sizes of 1
call SetFatesGlobalElements2(use_fates)
call t_stopf('fates_globals2')
return
end subroutine CLMFatesGlobals2
! ===================================================================================
subroutine CrossRefHistoryFields
! This routine only needs to be called on the masterproc.
! Here we cross reference the CLM history master
! list and make sure that all fields that start
! with fates have been allocated. If it has
! not, then we give a more constructive error
! message than what is possible in PIO. The user
! most likely needs to increase the history density
! level
use histFileMod, only: getname
use histFileMod, only: hist_fincl1,hist_fincl2,hist_fincl3,hist_fincl4
use histFileMod, only: hist_fincl5,hist_fincl6,hist_fincl7,hist_fincl8
use histFileMod, only: hist_fincl9,hist_fincl10
use histFileMod, only: max_tapes, max_flds, max_namlen
integer :: t ! iterator index for history tapes
integer :: f ! iterator index for registered history field names
integer :: nh ! iterator index for fates registered history
logical :: is_fates_field ! Does this start with FATES_ ?
logical :: found ! if true, than the history field is either
! not part of the fates set, or was found in
! the fates set
character(len=64) :: fincl_name
! This is a copy of the public in histFileMod, copied
! here because it isn't filled at the time of this call
character(len=max_namlen+2) :: fincl(max_flds,max_tapes)
fincl(:,1) = hist_fincl1(:)
fincl(:,2) = hist_fincl2(:)
fincl(:,3) = hist_fincl3(:)
fincl(:,4) = hist_fincl4(:)
fincl(:,5) = hist_fincl5(:)
fincl(:,6) = hist_fincl6(:)
fincl(:,7) = hist_fincl7(:)
fincl(:,8) = hist_fincl8(:)
fincl(:,9) = hist_fincl9(:)
fincl(:,10) = hist_fincl10(:)
do t = 1,max_tapes
f = 1
search_fields: do while (f < max_flds .and. fincl(f,t) /= ' ')
fincl_name = getname(fincl(f,t))
is_fates_field = fincl_name(1:6)=='FATES_'
if(is_fates_field) then
found = .false.
do_fates_hist: do nh = 1,fates_hist%num_history_vars()
if(trim(fates_hist%hvars(nh)%vname) == &
trim(fincl_name)) then
found=.true.
exit do_fates_hist
end if
end do do_fates_hist
if(.not.found)then
write(iulog,*) 'the history field: ',trim(fincl_name)
write(iulog,*) 'was requested in the namelist, but was'
write(iulog,*) 'not found in the list of fates_hist%hvars.'
write(iulog,*) 'Most likely, this is because this history variable'
write(iulog,*) 'was specified in the user namelist, but the user'
write(iulog,*) 'specified a FATES history output dimension level'
write(iulog,*) 'that does not contain that variable in its valid set.'
write(iulog,*) 'You may have to increase the namelist setting: fates_history_dimlevel'
write(iulog,*) 'current fates_history_dimlevel: ',fates_history_dimlevel(:)
!uncomment if you want to list all fates history variables in registry
!do_fates_hist2: do nh = 1,fates_hist%num_history_vars()
! write(iulog,*) trim(fates_hist%hvars(nh)%vname)
!end do do_fates_hist2
call endrun(msg=errMsg(sourcefile, __LINE__))
end if
end if
f = f + 1
end do search_fields
end do
end subroutine CrossRefHistoryFields
! ===================================================================================
subroutine CLMFatesTimesteps()
hlm_stepsize = get_step_size_real()
call InitTimeAveragingGlobals()
return
end subroutine CLMFatesTimesteps
! ====================================================================================
subroutine init(this, bounds_proc, flandusepftdat)
! ---------------------------------------------------------------------------------
! This initializes the hlm_fates_interface_type
!
! sites is the root of the fates state hierarchy (instantaneous info on
! the state of the ecosystem). As such, it governs the connection points between
! the host (which also dictates its allocation) and its patch structures.
!
! sites may associate with different scales in different models. In
! CLM, it is being designed to relate to column scale.
!
! This global may become relegated to this module.
!
! Note: CLM/ALM currently wants sites to be allocated even if ed
! is not turned on
! ---------------------------------------------------------------------------------
use spmdMod, only : npes
use decompMod, only : procinfo
use FatesInterfaceTypesMod, only : numpft_fates => numpft
use FatesParameterDerivedMod, only : param_derived
use subgridMod, only : natveg_patch_exists
use clm_instur , only : wt_nat_patch
use FATESFireFactoryMod , only: create_fates_fire_data_method
! Input Arguments
class(hlm_fates_interface_type), intent(inout) :: this
type(bounds_type),intent(in) :: bounds_proc
character(len=*), intent(in) :: flandusepftdat
! local variables
integer :: nclumps ! Number of threads
integer :: nc ! thread index
integer :: s ! FATES site index
integer :: c ! HLM column index
integer :: l ! HLM LU index
integer :: g ! HLM grid index
integer :: m ! HLM PFT index
integer :: ft ! FATES PFT index
integer :: pi,pf
integer, allocatable :: collist (:)
type(bounds_type) :: bounds_clump
integer :: nmaxcol
integer :: ndecomp
integer :: numg
real(r8), allocatable :: landuse_pft_map(:,:,:)
real(r8), allocatable :: landuse_bareground(:)
! Initialize the FATES communicators with the HLM
! This involves to stages
! 1) allocate the vectors
! 2) add the history variables defined in clm_inst to the history machinery
call t_startf('fates_init')
! Parameter Routines
call param_derived%Init( numpft_fates )
! Initialize dispersal
if (fates_seeddisp_cadence /= fates_dispersal_cadence_none) then
! Initialize fates global seed dispersal array for all nodes
call get_proc_global(ng=numg)
call this%fates_seed%init(npes,numg,procinfo%ncells,numpft_fates)
! Initialize the array of nearest neighbors for fates-driven grid cell communications
! This must be called after surfrd_get_data and decompInit_lnd
call DetermineGridCellNeighbors(lneighbors,this%fates_seed,numg)
end if
nclumps = get_proc_clumps()
allocate(this%fates(nclumps))
allocate(this%f2hmap(nclumps))
if(debug)then
write(iulog,*) 'clm_fates%init(): allocating for ',nclumps,' threads'
end if
! Retrieve the landuse x pft static data if the file is present
if (use_fates_fixed_biogeog .and. use_fates_luh) then
call GetLandusePFTData(bounds_proc, flandusepftdat, landuse_pft_map, landuse_bareground)
end if
nclumps = get_proc_clumps()
allocate(copy_fates_var(bounds_proc%begc:bounds_proc%endc))
copy_fates_var(:) = .false.
!$OMP PARALLEL DO PRIVATE (nc,bounds_clump,nmaxcol,s,c,l,g,collist,pi,pf,ft)
do nc = 1,nclumps
call get_clump_bounds(nc, bounds_clump)
nmaxcol = bounds_clump%endc - bounds_clump%begc + 1
allocate(collist(1:nmaxcol))
! Allocate the mapping that points columns to FATES sites, 0 is NA
allocate(this%f2hmap(nc)%hsites(bounds_clump%begc:bounds_clump%endc))
! Initialize all columns with a zero index, which indicates no FATES site
this%f2hmap(nc)%hsites(:) = 0
s = 0
do c = bounds_clump%begc,bounds_clump%endc
l = col%landunit(c)
! These are the key constraints that determine if this column
! will have a FATES site associated with it
! INTERF-TODO: WE HAVE NOT FILTERED OUT FATES SITES ON INACTIVE COLUMNS.. YET
! NEED A RUN-TIME ROUTINE THAT CLEARS AND REWRITES THE SITE LIST
if (lun%itype(l) == istsoil ) then
s = s + 1
collist(s) = c
this%f2hmap(nc)%hsites(c) = s
col%is_fates(c) = .true.
if(debug)then
write(iulog,*) 'clm_fates%init(): thread',nc,': found column',c,'with lu',l
write(iulog,*) 'LU type:', lun%itype(l)
end if
endif
enddo
if(debug)then
write(iulog,*) 'clm_fates%init(): thread',nc,': allocated ',s,' sites'
end if
! Allocate vectors that match FATES sites with HLM columns
! RGK: Sites and fcolumns are forced as args during clm_driv() as of 6/4/2016
! We may have to give these a dummy allocation of 1, which should
! not be a problem since we always iterate on nsites.
allocate(this%f2hmap(nc)%fcolumn(s))
! Assign the h2hmap indexing
this%f2hmap(nc)%fcolumn(1:s) = collist(1:s)
! Deallocate the temporary arrays
deallocate(collist)
! Set the number of FATES sites
this%fates(nc)%nsites = s
! Allocate the FATES sites
allocate (this%fates(nc)%sites(this%fates(nc)%nsites))
! Allocate the FATES boundary arrays (in)
allocate(this%fates(nc)%bc_in(this%fates(nc)%nsites))
! Allocate the FATES boundary arrays (out)
allocate(this%fates(nc)%bc_out(this%fates(nc)%nsites))
! Parameter Constants defined by FATES, but used in ELM
! Note that FATES has its parameters defined, so we can also set the values
call allocate_bcpconst(this%fates(nc)%bc_pconst,nlevdecomp)
! This also needs
call set_bcpconst(this%fates(nc)%bc_pconst,nlevdecomp)
! Allocate and Initialize the Boundary Condition Arrays
! These are staticaly allocated at maximums, so
! No information about the patch or cohort structure is needed at this step
do s = 1, this%fates(nc)%nsites
c = this%f2hmap(nc)%fcolumn(s)
this%fates(nc)%sites(s)%h_gid = c
ndecomp = col%nbedrock(c)
call allocate_bcin(this%fates(nc)%bc_in(s),col%nbedrock(c),ndecomp, &
num_harvest_inst, num_landuse_state_vars, num_landuse_transition_vars, &
surfpft_lb,surfpft_ub)
call allocate_bcout(this%fates(nc)%bc_out(s),col%nbedrock(c),ndecomp)
call zero_bcs(this%fates(nc),s)
! Pass any grid-cell derived attributes to the site
! ---------------------------------------------------------------------------
c = this%f2hmap(nc)%fcolumn(s)
g = col%gridcell(c)
this%fates(nc)%sites(s)%lat = grc%latdeg(g)
this%fates(nc)%sites(s)%lon = grc%londeg(g)
! Transfer the landuse x pft data to fates via bc_in if file is given
if (use_fates_fixed_biogeog) then
if (use_fates_luh) then
this%fates(nc)%bc_in(s)%pft_areafrac_lu(:,1:num_landuse_pft_vars) = landuse_pft_map(g,:,1:num_landuse_pft_vars)
this%fates(nc)%bc_in(s)%baregroundfrac = landuse_bareground(g)
else
! initialize static layers for reduced complexity FATES versions from HLM
! maybe make this into a subroutine of it's own later.
this%fates(nc)%bc_in(s)%pft_areafrac(:)=0._r8
do m = surfpft_lb,surfpft_ub
ft = m - surfpft_lb
this%fates(nc)%bc_in(s)%pft_areafrac(ft)=wt_nat_patch(g,m)
end do
if (abs(sum(this%fates(nc)%bc_in(s)%pft_areafrac(surfpft_lb:surfpft_ub)) - 1.0_r8) > sum_to_1_tol) then