-
Notifications
You must be signed in to change notification settings - Fork 92
/
EDCohortDynamicsMod.F90
2447 lines (1991 loc) · 111 KB
/
EDCohortDynamicsMod.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 EDCohortDynamicsMod
!
! !DESCRIPTION:
! Cohort stuctures in ED.
!
! !USES:
use FatesGlobals , only : endrun => fates_endrun
use FatesGlobals , only : fates_log
use FatesInterfaceTypesMod , only : hlm_freq_day
use FatesInterfaceTypesMod , only : bc_in_type
use FatesInterfaceTypesMod , only : hlm_use_planthydro
use FatesInterfaceTypesMod , only : hlm_use_sp
use FatesInterfaceTypesMod , only : hlm_use_cohort_age_tracking
use FatesInterfaceTypesMod , only : hlm_use_tree_damage
use FatesInterfaceTypesMod , only : hlm_is_restart
use FatesConstantsMod , only : r8 => fates_r8
use FatesConstantsMod , only : fates_unset_int
use FatesConstantsMod , only : itrue,ifalse
use FatesConstantsMod , only : fates_unset_r8
use FatesConstantsMod , only : nearzero
use FatesConstantsMod , only : calloc_abs_error
use FatesInterfaceTypesMod , only : hlm_days_per_year
use FatesInterfaceTypesMod , only : nleafage
use SFParamsMod , only : SF_val_CWD_frac
use EDPftvarcon , only : EDPftvarcon_inst
use EDPftvarcon , only : GetDecompyFrac
use PRTParametersMod , only : prt_params
use FatesParameterDerivedMod, only : param_derived
use EDTypesMod , only : ed_site_type, ed_patch_type, ed_cohort_type
use EDTypesMod , only : nclmax
use PRTGenericMod , only : element_list
use PRTGenericMod , only : StorageNutrientTarget
use FatesLitterMod , only : ncwd
use FatesLitterMod , only : ndcmpy
use FatesLitterMod , only : litter_type
use EDParamsMod , only : max_cohort_per_patch
use EDTypesMod , only : AREA
use EDTypesMod , only : min_npm2, min_nppatch
use EDTypesMod , only : min_n_safemath
use EDTypesMod , only : nlevleaf
use PRTGenericMod , only : max_nleafage
use EDTypesMod , only : ican_upper
use EDTypesMod , only : site_fluxdiags_type
use PRTGenericMod , only : num_elements
use EDTypesMod , only : leaves_on
use EDParamsMod , only : ED_val_cohort_age_fusion_tol
use FatesInterfaceTypesMod , only : hlm_use_planthydro
use FatesInterfaceTypesMod , only : hlm_parteh_mode
use FatesPlantHydraulicsMod, only : FuseCohortHydraulics
use FatesPlantHydraulicsMod, only : CopyCohortHydraulics
use FatesPlantHydraulicsMod, only : UpdateSizeDepPlantHydProps
use FatesPlantHydraulicsMod, only : InitPlantHydStates
use FatesPlantHydraulicsMod, only : InitHydrCohort
use FatesPlantHydraulicsMod, only : DeallocateHydrCohort
use FatesPlantHydraulicsMod, only : AccumulateMortalityWaterStorage
use FatesPlantHydraulicsMod, only : UpdatePlantHydrNodes
use FatesPlantHydraulicsMod, only : UpdatePlantHydrLenVol
use FatesPlantHydraulicsMod, only : UpdatePlantKmax
use FatesPlantHydraulicsMod, only : SavePreviousCompartmentVolumes
use FatesPlantHydraulicsMod, only : ConstrainRecruitNumber
use FatesSizeAgeTypeIndicesMod, only : sizetype_class_index
use FatesSizeAgeTypeIndicesMod, only : coagetype_class_index
use FatesAllometryMod , only : bleaf
use FatesAllometryMod , only : bfineroot
use FatesAllometryMod , only : bsap_allom
use FatesAllometryMod , only : bagw_allom
use FatesAllometryMod , only : bbgw_allom
use FatesAllometryMod , only : bdead_allom
use FatesAllometryMod , only : h_allom
use FatesAllometryMod , only : carea_allom
use FatesAllometryMod , only : bstore_allom
use FatesAllometryMod , only : ForceDBH
use FatesAllometryMod , only : tree_lai, tree_sai
use FatesAllometryMod , only : set_root_fraction
use PRTGenericMod, only : prt_carbon_allom_hyp
use PRTGenericMod, only : prt_cnp_flex_allom_hyp
use PRTGenericMod, only : prt_vartypes
use PRTGenericMod, only : carbon12_element
use PRTGenericMod, only : nitrogen_element
use PRTGenericMod, only : phosphorus_element
use PRTGenericMod, only : leaf_organ
use PRTGenericMod, only : fnrt_organ
use PRTGenericMod, only : sapw_organ
use PRTGenericMod, only : store_organ
use PRTGenericMod, only : repro_organ
use PRTGenericMod, only : struct_organ
use PRTGenericMod, only : SetState
use PRTAllometricCarbonMod, only : callom_prt_vartypes
use PRTAllometricCarbonMod, only : ac_bc_inout_id_netdc
use PRTAllometricCarbonMod, only : ac_bc_in_id_pft
use PRTAllometricCarbonMod, only : ac_bc_in_id_ctrim
use PRTAllometricCarbonMod, only : ac_bc_inout_id_dbh
use PRTAllometricCarbonMod, only : ac_bc_in_id_lstat, ac_bc_in_id_cdamage
use PRTAllometricCNPMod, only : cnp_allom_prt_vartypes
use PRTAllometricCNPMod, only : acnp_bc_in_id_pft, acnp_bc_in_id_ctrim
use PRTAllometricCNPMod, only : acnp_bc_in_id_lstat, acnp_bc_inout_id_dbh
use PRTAllometricCNPMod, only : acnp_bc_inout_id_l2fr
use PRTAllometricCNPMod, only : acnp_bc_inout_id_cx_int
use PRTAllometricCNPMod, only : acnp_bc_inout_id_cx0
use PRTAllometricCNPMod, only : acnp_bc_inout_id_emadcxdt
use PRTAllometricCNPMod, only : acnp_bc_in_id_nc_repro
use PRTAllometricCNPMod, only : acnp_bc_in_id_pc_repro
use PRTAllometricCNPMod, only : acnp_bc_inout_id_resp_excess, acnp_bc_in_id_netdc
use PRTAllometricCNPMod, only : acnp_bc_inout_id_netdn, acnp_bc_inout_id_netdp
use PRTAllometricCNPMod, only : acnp_bc_out_id_cefflux, acnp_bc_out_id_nefflux
use PRTAllometricCNPMod, only : acnp_bc_out_id_pefflux, acnp_bc_out_id_limiter
use PRTAllometricCNPMod, only : acnp_bc_in_id_cdamage
use DamageMainMod, only : undamaged_class
use shr_infnan_mod, only : nan => shr_infnan_nan, assignment(=)
use shr_log_mod, only : errMsg => shr_log_errMsg
!
implicit none
private
!
public :: create_cohort
public :: zero_cohort
public :: nan_cohort
public :: terminate_cohorts
public :: terminate_cohort
public :: fuse_cohorts
public :: insert_cohort
public :: sort_cohorts
public :: copy_cohort
public :: count_cohorts
public :: InitPRTObject
public :: InitPRTBoundaryConditions
public :: SendCohortToLitter
public :: UpdateCohortBioPhysRates
public :: DeallocateCohort
public :: EvaluateAndCorrectDBH
public :: DamageRecovery
logical, parameter :: debug = .false. ! local debug flag
character(len=*), parameter, private :: sourcefile = &
__FILE__
integer, parameter, private :: conserve_crownarea_and_number_not_dbh = 1
integer, parameter, private :: conserve_dbh_and_number_not_crownarea = 2
integer, parameter, private :: cohort_fusion_conservation_method = conserve_crownarea_and_number_not_dbh
! 10/30/09: Created by Rosie Fisher
!-------------------------------------------------------------------------------------!
contains
!-------------------------------------------------------------------------------------!
subroutine create_cohort(currentSite, patchptr, pft, nn, hite, coage, dbh, &
prt, status, recruitstatus,ctrim, carea, clayer, crowndamage, spread, bc_in)
!
! !DESCRIPTION:
! create new cohort
! There are 4 places this is called
! 1) Initializing new cohorts at the beginning of a cold-start simulation
! 2) Initializing new recruits during dynamics
! 3) Initializing new cohorts at the beginning of a inventory read
! 4) Initializing new cohorts during restart
!
! It is assumed that in the first 3, this is called with a reasonable amount of starter information.
!
! !USES:
!
! !ARGUMENTS
type(ed_site_type), intent(inout), target :: currentSite
type(ed_patch_type), intent(inout), pointer :: patchptr
integer, intent(in) :: pft ! Cohort Plant Functional Type
integer, intent(in) :: crowndamage ! Cohort damage class
integer, intent(in) :: clayer ! canopy status of cohort
! (1 = canopy, 2 = understorey, etc.)
integer, intent(in) :: status ! growth status of plant
! (2 = leaves on , 1 = leaves off)
integer, intent(in) :: recruitstatus ! recruit status of plant
! (1 = recruitment , 0 = other)
real(r8), intent(in) :: nn ! number of individuals in cohort
! per 'area' (10000m2 default)
real(r8), intent(in) :: hite ! height: meters
real(r8), intent(in) :: coage ! cohort age in years
real(r8), intent(in) :: dbh ! dbh: cm
class(prt_vartypes),intent(inout), pointer :: prt ! The allocated PARTEH
!class(prt_vartypes),target :: prt ! The allocated PARTEH
! object
real(r8), intent(in) :: ctrim ! What is the fraction of the maximum
! leaf biomass that we are targeting?
real(r8), intent(in) :: spread ! The community assembly effects how
! spread crowns are in horizontal space
real(r8), intent(in) :: carea ! area of cohort ONLY USED IN SP MODE.
type(bc_in_type), intent(in) :: bc_in ! External boundary conditions
! !LOCAL VARIABLES:
type(ed_cohort_type), pointer :: new_cohort ! Pointer to New Cohort structure.
type(ed_cohort_type), pointer :: storesmallcohort
type(ed_cohort_type), pointer :: storebigcohort
integer :: iage ! loop counter for leaf age classes
real(r8) :: leaf_c ! total leaf carbon
integer :: tnull,snull ! are the tallest and shortest cohorts allocate
integer :: nlevrhiz ! number of rhizosphere layers
!----------------------------------------------------------------------
allocate(new_cohort)
call nan_cohort(new_cohort) ! Make everything in the cohort not-a-number
call zero_cohort(new_cohort) ! Zero things that need to be zeroed.
! Point to the PARTEH object
new_cohort%prt => prt
! The PARTEH cohort object should be allocated and already
! initialized in this routine.
call new_cohort%prt%CheckInitialConditions()
!**********************/
! Define cohort state variable
!**********************/
new_cohort%indexnumber = fates_unset_int ! Cohort indexing was not thread-safe, setting
! bogus value for the time being (RGK-012017)
new_cohort%patchptr => patchptr
new_cohort%pft = pft
new_cohort%crowndamage = crowndamage
new_cohort%status_coh = status
new_cohort%n = nn
new_cohort%hite = hite
new_cohort%dbh = dbh
new_cohort%coage = coage
new_cohort%canopy_trim = ctrim
new_cohort%canopy_layer = clayer
new_cohort%canopy_layer_yesterday = real(clayer, r8)
! Initialize the leaf to fineroot biomass ratio
! for C-only, this will stay constant, for nutrient enabled
! this will be dynamic. In both cases, new cohorts are
! initialized with the minimum. This works in the nutrient
! enabled case, because cohorts are also initialized with
! full stores, which match with minimum fr biomass
new_cohort%l2fr = prt_params%allom_l2fr(pft)
if(hlm_parteh_mode .eq. prt_cnp_flex_allom_hyp) then
new_cohort%cx_int = 0._r8 ! Assume balanced N,P/C stores ie log(1) = 0
new_cohort%cx0 = 0._r8 ! Assume balanced N,P/C stores ie log(1) = 0
new_cohort%ema_dcxdt = 0._r8 ! Assume unchanged dCX/dt
new_cohort%cnp_limiter = 0 ! Assume limitations are unknown
end if
! This sets things like vcmax25top, that depend on the
! leaf age fractions (which are defined by PARTEH)
call UpdateCohortBioPhysRates(new_cohort)
call sizetype_class_index(new_cohort%dbh, new_cohort%pft, &
new_cohort%size_class,new_cohort%size_by_pft_class)
! If cohort age trackign is off we call this here once
! just so everythin is in the first bin -
! this makes it easier to copy and terminate cohorts later
! we don't need to update this ever if cohort age tracking is off
call coagetype_class_index(new_cohort%coage, new_cohort%pft, &
new_cohort%coage_class,new_cohort%coage_by_pft_class)
! This routine may be called during restarts, and at this point in the call sequence
! the actual cohort data is unknown, as this is really only used for allocation
! In these cases, testing if things like biomass are reasonable is pre-mature
! However, in this part of the code, we will pass in nominal values for size, number and type
if (new_cohort%dbh <= 0._r8 .or. new_cohort%n == 0._r8 .or. new_cohort%pft == 0 ) then
write(fates_log(),*) 'ED: something is zero in create_cohort', &
new_cohort%dbh,new_cohort%n, &
new_cohort%pft
call endrun(msg=errMsg(sourcefile, __LINE__))
endif
! Assign canopy extent and depth
if(hlm_use_sp.eq.ifalse)then
call carea_allom(new_cohort%dbh,new_cohort%n,spread,new_cohort%pft, &
new_cohort%crowndamage,new_cohort%c_area)
else
new_cohort%c_area = carea ! set this from previously precision-controlled value in SP mode
endif
! Query PARTEH for the leaf carbon [kg]
leaf_c = new_cohort%prt%GetState(leaf_organ,carbon12_element)
new_cohort%treelai = tree_lai(leaf_c, new_cohort%pft, new_cohort%c_area, &
new_cohort%n, new_cohort%canopy_layer, &
patchptr%canopy_layer_tlai,new_cohort%vcmax25top )
if(hlm_use_sp.eq.ifalse)then
new_cohort%treesai = tree_sai(new_cohort%pft, new_cohort%dbh, &
new_cohort%crowndamage, new_cohort%canopy_trim, &
new_cohort%c_area, new_cohort%n, new_cohort%canopy_layer, &
patchptr%canopy_layer_tlai, new_cohort%treelai,new_cohort%vcmax25top,2 )
end if
! Put cohort at the right place in the linked list
storebigcohort => patchptr%tallest
storesmallcohort => patchptr%shortest
if (associated(patchptr%tallest)) then
tnull = 0
else
tnull = 1
patchptr%tallest => new_cohort
endif
if (associated(patchptr%shortest)) then
snull = 0
else
snull = 1
patchptr%shortest => new_cohort
endif
! Allocate running mean functions
! (Keeping as an example)
!! allocate(new_cohort%tveg_lpa)
!! call new_cohort%tveg_lpa%InitRMean(ema_lpa,init_value=patchptr%tveg_lpa%GetMean())
call InitPRTBoundaryConditions(new_cohort)
! Recuits do not have mortality rates, nor have they moved any
! carbon when they are created. They will bias our statistics
! until they have experienced a full day. We need a newly recruited flag.
! This flag will be set to false after it has experienced
! growth, disturbance and mortality.
new_cohort%isnew = .true.
if( hlm_use_planthydro.eq.itrue ) then
nlevrhiz = currentSite%si_hydr%nlevrhiz
! This allocates array spaces
call InitHydrCohort(currentSite,new_cohort)
! zero out the water balance error
new_cohort%co_hydr%errh2o = 0._r8
! This calculates node heights
call UpdatePlantHydrNodes(new_cohort,new_cohort%pft, &
new_cohort%hite,currentSite%si_hydr)
! This calculates volumes and lengths
call UpdatePlantHydrLenVol(new_cohort,currentSite%si_hydr)
! This updates the Kmax's of the plant's compartments
call UpdatePlantKmax(new_cohort%co_hydr,new_cohort,currentSite%si_hydr)
! Since this is a newly initialized plant, we set the previous compartment-size
! equal to the ones we just calculated.
call SavePreviousCompartmentVolumes(new_cohort%co_hydr)
! This comes up with starter suctions and then water contents
! based on the soil values
call InitPlantHydStates(currentSite,new_cohort)
if(recruitstatus==1)then
new_cohort%co_hydr%is_newly_recruited = .true.
! If plant hydraulics is active, we must constrain the
! number density of the new recruits based on the moisture
! available to be subsumed in the new plant tissues.
! So we go through the process of pre-initializing the hydraulic
! states in the temporary cohort, to calculate this new number density
call ConstrainRecruitNumber(currentSite,new_cohort, bc_in)
endif
endif
call insert_cohort(new_cohort, patchptr%tallest, patchptr%shortest, tnull, snull, &
storebigcohort, storesmallcohort)
patchptr%tallest => storebigcohort
patchptr%shortest => storesmallcohort
end subroutine create_cohort
! -------------------------------------------------------------------------------------
subroutine InitPRTBoundaryConditions(new_cohort)
! Set the boundary conditions that flow in an out of the PARTEH
! allocation hypotheses. Each of these calls to "RegsterBC" are simply
! setting pointers.
! For instance, if the hypothesis wants to know what
! the DBH of the plant is, then we pass in the dbh as an argument (new_cohort%dbh),
! and also tell it which boundary condition we are talking about (which is
! defined by an integer index (ac_bc_inout_id_dbh)
!
! Again, elaborated Example:
! "ac_bc_inout_id_dbh" is the unique integer that defines the object index
! for the allometric carbon "ac" boundary condition "bc" for DBH "dbh"
! that is classified as input and output "inout".
! See PRTAllometricCarbonMod.F90 to track its usage.
! bc_rval is used as the optional argument identifyer to specify a real
! value boundary condition.
! bc_ival is used as the optional argument identifyer to specify an integer
! value boundary condition.
type(ed_cohort_type), intent(inout), target :: new_cohort
select case(hlm_parteh_mode)
case (prt_carbon_allom_hyp)
! Register boundary conditions for the Carbon Only Allometric Hypothesis
call new_cohort%prt%RegisterBCInOut(ac_bc_inout_id_dbh,bc_rval = new_cohort%dbh)
call new_cohort%prt%RegisterBCInOut(ac_bc_inout_id_netdc,bc_rval = new_cohort%npp_acc)
call new_cohort%prt%RegisterBCIn(ac_bc_in_id_cdamage,bc_ival = new_cohort%crowndamage)
call new_cohort%prt%RegisterBCIn(ac_bc_in_id_pft,bc_ival = new_cohort%pft)
call new_cohort%prt%RegisterBCIn(ac_bc_in_id_ctrim,bc_rval = new_cohort%canopy_trim)
call new_cohort%prt%RegisterBCIn(ac_bc_in_id_lstat,bc_ival = new_cohort%status_coh)
case (prt_cnp_flex_allom_hyp)
call new_cohort%prt%RegisterBCIn(acnp_bc_in_id_pft,bc_ival = new_cohort%pft)
call new_cohort%prt%RegisterBCIn(acnp_bc_in_id_ctrim,bc_rval = new_cohort%canopy_trim)
call new_cohort%prt%RegisterBCIn(acnp_bc_in_id_lstat,bc_ival = new_cohort%status_coh)
call new_cohort%prt%RegisterBCIn(acnp_bc_in_id_netdc, bc_rval = new_cohort%npp_acc)
call new_cohort%prt%RegisterBCIn(acnp_bc_in_id_nc_repro,bc_rval = new_cohort%nc_repro)
call new_cohort%prt%RegisterBCIn(acnp_bc_in_id_pc_repro,bc_rval = new_cohort%pc_repro)
call new_cohort%prt%RegisterBCIn(acnp_bc_in_id_cdamage,bc_ival = new_cohort%crowndamage)
call new_cohort%prt%RegisterBCInOut(acnp_bc_inout_id_dbh,bc_rval = new_cohort%dbh)
call new_cohort%prt%RegisterBCInOut(acnp_bc_inout_id_resp_excess,bc_rval = new_cohort%resp_excess)
call new_cohort%prt%RegisterBCInOut(acnp_bc_inout_id_l2fr,bc_rval = new_cohort%l2fr)
call new_cohort%prt%RegisterBCInOut(acnp_bc_inout_id_cx_int,bc_rval = new_cohort%cx_int)
call new_cohort%prt%RegisterBCInOut(acnp_bc_inout_id_emadcxdt,bc_rval = new_cohort%ema_dcxdt)
call new_cohort%prt%RegisterBCInOut(acnp_bc_inout_id_cx0,bc_rval = new_cohort%cx0)
call new_cohort%prt%RegisterBCInOut(acnp_bc_inout_id_netdn, bc_rval = new_cohort%daily_n_gain)
call new_cohort%prt%RegisterBCInOut(acnp_bc_inout_id_netdp, bc_rval = new_cohort%daily_p_gain)
call new_cohort%prt%RegisterBCOut(acnp_bc_out_id_cefflux, bc_rval = new_cohort%daily_c_efflux)
call new_cohort%prt%RegisterBCOut(acnp_bc_out_id_nefflux, bc_rval = new_cohort%daily_n_efflux)
call new_cohort%prt%RegisterBCOut(acnp_bc_out_id_pefflux, bc_rval = new_cohort%daily_p_efflux)
call new_cohort%prt%RegisterBCOut(acnp_bc_out_id_limiter, bc_ival = new_cohort%cnp_limiter)
case DEFAULT
write(fates_log(),*) 'You specified an unknown PRT module'
write(fates_log(),*) 'Aborting'
call endrun(msg=errMsg(sourcefile, __LINE__))
end select
end subroutine InitPRTBoundaryConditions
! ------------------------------------------------------------------------------------!
subroutine InitPRTObject(prt)
! -----------------------------------------------------------------------------------
!
! This routine allocates the PARTEH object that is associated with each cohort.
! The argument that is passed in is a pointer that is then associated with this
! newly allocated object.
! The object that is allocated is the specific extended class for the hypothesis
! of choice.
! Following this, the object and its internal mappings are initialized.
! This routine does NOT set any of the initial conditions, or boundary conditions
! such as the organ/element masses. Those are handled after this call.
!
! -----------------------------------------------------------------------------------
! Argument
class(prt_vartypes), pointer :: prt
! Potential Extended types
class(callom_prt_vartypes), pointer :: c_allom_prt
class(cnp_allom_prt_vartypes), pointer :: cnp_allom_prt
select case(hlm_parteh_mode)
case (prt_carbon_allom_hyp)
allocate(c_allom_prt)
prt => c_allom_prt
case (prt_cnp_flex_allom_hyp)
allocate(cnp_allom_prt)
prt => cnp_allom_prt
case DEFAULT
write(fates_log(),*) 'You specified an unknown PRT module'
write(fates_log(),*) 'Aborting'
call endrun(msg=errMsg(sourcefile, __LINE__))
end select
! This is the call to allocate the data structures in the PRT object
! This call will be extended to each specific class.
call prt%InitPRTVartype()
return
end subroutine InitPRTObject
!-------------------------------------------------------------------------------------!
subroutine nan_cohort(cc_p)
!
! !DESCRIPTION:
! Make all the cohort variables NaN so they aren't used before defined.
!
! !USES:
use FatesConstantsMod, only : fates_unset_int
!
! !ARGUMENTS
type (ed_cohort_type), intent(inout), target :: cc_p
!
! !LOCAL VARIABLES:
type (ed_cohort_type) , pointer :: currentCohort
!----------------------------------------------------------------------
currentCohort => cc_p
currentCohort%taller => null() ! pointer to next tallest cohort
currentCohort%shorter => null() ! pointer to next shorter cohort
currentCohort%patchptr => null() ! pointer to patch that cohort is in
nullify(currentCohort%taller)
nullify(currentCohort%shorter)
nullify(currentCohort%patchptr)
! VEGETATION STRUCTURE
currentCohort%pft = fates_unset_int ! pft number
currentCohort%crowndamage = fates_unset_int ! Crown damage class
currentCohort%indexnumber = fates_unset_int ! unique number for each cohort. (within clump?)
currentCohort%canopy_layer = fates_unset_int ! canopy status of cohort (1 = canopy, 2 = understorey, etc.)
currentCohort%canopy_layer_yesterday = nan ! recent canopy status of cohort (1 = canopy, 2 = understorey, etc.)
currentCohort%NV = fates_unset_int ! Number of leaf layers: -
currentCohort%status_coh = fates_unset_int ! growth status of plant (2 = leaves on , 1 = leaves off)
currentCohort%size_class = fates_unset_int ! size class index
currentCohort%size_class_lasttimestep = fates_unset_int ! size class index
currentCohort%size_by_pft_class = fates_unset_int ! size by pft classification index
currentCohort%coage_class = fates_unset_int ! cohort age class index
currentCohort%coage_by_pft_class = fates_unset_int ! cohort age by pft class index
currentCohort%n = nan ! number of individuals in cohort per 'area' (10000m2 default)
currentCohort%dbh = nan ! 'diameter at breast height' in cm
currentCohort%coage = nan ! age of the cohort in years
currentCohort%hite = nan ! height: meters
currentCohort%g_sb_laweight = nan ! Total leaf conductance of cohort (stomata+blayer) weighted by leaf-area [m/s]*[m2]
currentCohort%canopy_trim = nan ! What is the fraction of the maximum leaf biomass that we are targeting? :-
currentCohort%leaf_cost = nan ! How much does it cost to maintain leaves: kgC/m2/year-1
currentCohort%excl_weight = nan ! How much of this cohort is demoted each year, as a proportion of all cohorts:-
currentCohort%prom_weight = nan ! How much of this cohort is promoted each year, as a proportion of all cohorts:-
currentCohort%c_area = nan ! areal extent of canopy (m2)
currentCohort%treelai = nan ! lai of tree (total leaf area (m2) / canopy area (m2)
currentCohort%treesai = nan ! stem area index of tree (total stem area (m2) / canopy area (m2)
currentCohort%seed_prod = nan
currentCohort%vcmax25top = nan
currentCohort%jmax25top = nan
currentCohort%tpu25top = nan
currentCohort%kp25top = nan
! CARBON FLUXES
currentCohort%gpp_acc_hold = nan ! GPP: kgC/indiv/year
currentCohort%gpp_tstep = nan ! GPP: kgC/indiv/timestep
currentCohort%gpp_acc = nan ! GPP: kgC/indiv/day
currentCohort%npp_acc_hold = nan ! NPP: kgC/indiv/year
currentCohort%npp_tstep = nan ! NPP: kGC/indiv/timestep
currentCohort%npp_acc = nan ! NPP: kgC/indiv/day
currentCohort%year_net_uptake(:) = nan ! Net uptake of individual leaf layers kgC/m2/year
currentCohort%ts_net_uptake(:) = nan ! Net uptake of individual leaf layers kgC/m2/s
currentCohort%resp_acc_hold = nan ! RESP: kgC/indiv/year
currentCohort%resp_tstep = nan ! RESP: kgC/indiv/timestep
currentCohort%resp_acc = nan ! RESP: kGC/cohort/day
! Fluxes from nutrient allocation
currentCohort%daily_nh4_uptake = nan
currentCohort%daily_no3_uptake = nan
currentCohort%daily_n_gain = nan
currentCohort%sym_nfix_daily = nan
currentCohort%sym_nfix_tstep = nan
currentCohort%daily_p_gain = nan
currentCohort%daily_c_efflux = nan
currentCohort%daily_n_efflux = nan
currentCohort%daily_p_efflux = nan
currentCohort%daily_n_demand = nan
currentCohort%daily_p_demand = nan
currentCohort%cx_int = nan
currentCohort%cx0 = nan
currentCohort%ema_dcxdt = nan
currentCohort%cnp_limiter = fates_unset_int
currentCohort%c13disc_clm = nan ! C13 discrimination, per mil at indiv/timestep
currentCohort%c13disc_acc = nan ! C13 discrimination, per mil at indiv/timestep at indiv/daily at the end of a day
!RESPIRATION
currentCohort%rdark = nan
currentCohort%resp_m = nan ! Maintenance respiration. kGC/cohort/year
currentCohort%resp_m_unreduced = nan ! Diagnostic-only unreduced Maintenance respiration. kGC/cohort/year
currentCohort%resp_excess = nan ! Respiration of excess (unallocatable) carbon (kg/indiv/day)
currentCohort%livestem_mr = nan ! Live stem maintenance respiration. kgC/indiv/s-1
currentCohort%livecroot_mr = nan ! Coarse root maintenance respiration. kgC/indiv/s-1
currentCohort%froot_mr = nan ! Fine root maintenance respiration. kgC/indiv/s-1
currentCohort%resp_g_tstep = nan ! Growth respiration. kGC/indiv/timestep
! ALLOCATION
currentCohort%dmort = nan ! proportional mortality rate. (year-1)
! logging
currentCohort%lmort_direct = nan
currentCohort%lmort_infra = nan
currentCohort%lmort_collateral = nan
currentCohort%l_degrad = nan
currentCohort%c_area = nan ! areal extent of canopy (m2)
currentCohort%treelai = nan ! lai of tree (total leaf area (m2) / canopy area (m2)
currentCohort%treesai = nan ! stem area index of tree (total stem area (m2) / canopy area (m2)
! VARIABLES NEEDED FOR INTEGRATION
currentCohort%dndt = nan ! time derivative of cohort size
currentCohort%dhdt = nan ! time derivative of height
currentCohort%ddbhdt = nan ! time derivative of dbh
! FIRE
currentCohort%fraction_crown_burned = nan ! proportion of crown affected by fire
currentCohort%cambial_mort = nan ! probability that trees dies due to cambial char P&R (1986)
currentCohort%crownfire_mort = nan ! probability of tree post-fire mortality due to crown scorch
currentCohort%fire_mort = nan ! post-fire mortality from cambial and crown damage assuming two are independent
end subroutine nan_cohort
!-------------------------------------------------------------------------------------!
subroutine zero_cohort(cc_p)
!
! !DESCRIPTION:
! Zero variables that need to be accounted for if
! this cohort is altered before they are defined.
!
! !USES:
!
! !ARGUMENTS
type (ed_cohort_type), intent(inout), target :: cc_p
!
! !LOCAL VARIABLES:
type (ed_cohort_type) , pointer :: currentCohort
!----------------------------------------------------------------------
currentCohort => cc_p
currentCohort%NV = 0
currentCohort%status_coh = 0
currentCohort%rdark = 0._r8
currentCohort%resp_m = 0._r8
currentCohort%resp_m_unreduced = 0._r8
currentCohort%resp_excess = 0._r8
currentCohort%resp_g_tstep = 0._r8
currentCohort%livestem_mr = 0._r8
currentCohort%livecroot_mr = 0._r8
currentCohort%froot_mr = 0._r8
currentCohort%fire_mort = 0._r8
currentcohort%npp_acc = 0._r8
currentcohort%gpp_acc = 0._r8
currentcohort%resp_acc = 0._r8
currentcohort%npp_tstep = 0._r8
currentcohort%gpp_tstep = 0._r8
currentcohort%resp_tstep = 0._r8
currentcohort%resp_acc_hold = 0._r8
currentcohort%year_net_uptake(:) = 999._r8 ! this needs to be 999, or trimming of new cohorts will break.
currentcohort%ts_net_uptake(:) = 0._r8
currentcohort%fraction_crown_burned = 0._r8
currentCohort%size_class = 1
currentCohort%coage_class = 1
currentCohort%seed_prod = 0._r8
currentCohort%size_class_lasttimestep = 0
currentcohort%npp_acc_hold = 0._r8
currentcohort%gpp_acc_hold = 0._r8
currentcohort%dmort = 0._r8
currentcohort%g_sb_laweight = 0._r8
currentcohort%treesai = 0._r8
currentCohort%lmort_direct = 0._r8
currentCohort%lmort_infra = 0._r8
currentCohort%lmort_collateral = 0._r8
currentCohort%l_degrad = 0._r8
currentCohort%leaf_cost = 0._r8
currentcohort%excl_weight = 0._r8
currentcohort%prom_weight = 0._r8
currentcohort%crownfire_mort = 0._r8
currentcohort%cambial_mort = 0._r8
currentCohort%c13disc_clm = 0._r8
currentCohort%c13disc_acc = 0._r8
! Daily nutrient fluxes are INTEGRATED over the course of the
! day. This variable MUST be zerod upon creation AND
! after allocation. These variables exist in
! carbon-only mode but are not used.
currentCohort%daily_nh4_uptake = 0._r8
currentCohort%daily_no3_uptake = 0._r8
currentCohort%daily_p_gain = 0._r8
currentCohort%daily_c_efflux = 0._r8
currentCohort%daily_n_efflux = 0._r8
currentCohort%daily_p_efflux = 0._r8
! Initialize these as negative
currentCohort%daily_p_demand = -9._r8
currentCohort%daily_n_demand = -9._r8
! Fixation is also integrated over the course of the day
! and must be zeroed upon creation and after plant
! resource allocation
currentCohort%sym_nfix_daily = 0._r8
end subroutine zero_cohort
!-------------------------------------------------------------------------------------!
subroutine terminate_cohorts( currentSite, currentPatch, level , call_index, bc_in)
!
! !DESCRIPTION:
! terminates all cohorts when they get too small
!
! !USES:
!
! !ARGUMENTS
type (ed_site_type) , intent(inout) :: currentSite
type (ed_patch_type), intent(inout) :: currentPatch
integer , intent(in) :: level
integer :: call_index
type(bc_in_type), intent(in) :: bc_in
! Important point regarding termination levels. Termination is typically
! called after fusion. We do this so that we can re-capture the biomass that would
! otherwise be lost from termination. The biomass of a fused plant remains in the
! live pool. However, some plant number densities can be so low that they
! can cause numerical instabilities. Thus, we call terminate_cohorts at level=1
! before fusion to get rid of these cohorts that are so incredibly sparse, and then
! terminate the remainder at level 2 for various other reasons.
!
! !LOCAL VARIABLES:
type (ed_cohort_type) , pointer :: currentCohort
type (ed_cohort_type) , pointer :: shorterCohort
type (ed_cohort_type) , pointer :: tallerCohort
real(r8) :: leaf_c ! leaf carbon [kg]
real(r8) :: store_c ! storage carbon [kg]
real(r8) :: sapw_c ! sapwood carbon [kg]
real(r8) :: fnrt_c ! fineroot carbon [kg]
real(r8) :: repro_c ! reproductive carbon [kg]
real(r8) :: struct_c ! structural carbon [kg]
integer :: terminate ! do we terminate (itrue) or not (ifalse)
integer :: istat ! return status code
character(len=255) :: smsg
!----------------------------------------------------------------------
currentCohort => currentPatch%shortest
do while (associated(currentCohort))
terminate = ifalse
tallerCohort => currentCohort%taller
leaf_c = currentCohort%prt%GetState(leaf_organ, carbon12_element)
store_c = currentCohort%prt%GetState(store_organ, carbon12_element)
sapw_c = currentCohort%prt%GetState(sapw_organ, carbon12_element)
fnrt_c = currentCohort%prt%GetState(fnrt_organ, carbon12_element)
struct_c = currentCohort%prt%GetState(struct_organ, carbon12_element)
repro_c = currentCohort%prt%GetState(repro_organ, carbon12_element)
! Check if number density is so low is breaks math (level 1)
if (currentcohort%n < min_n_safemath .and. level == 1) then
terminate = itrue
if ( debug ) then
write(fates_log(),*) 'terminating cohorts 0',currentCohort%n/currentPatch%area,currentCohort%dbh,currentCohort%pft,call_index
endif
endif
! The rest of these are only allowed if we are not dealing with a recruit (level 2)
if (.not.currentCohort%isnew .and. level == 2) then
! Not enough n or dbh
if (currentCohort%n/currentPatch%area <= min_npm2 .or. & !
currentCohort%n <= min_nppatch .or. &
(currentCohort%dbh < 0.00001_r8 .and. store_c < 0._r8) ) then
terminate = itrue
if ( debug ) then
write(fates_log(),*) 'terminating cohorts 1',currentCohort%n/currentPatch%area,currentCohort%dbh,currentCohort%pft,call_index
endif
endif
! Outside the maximum canopy layer
if (currentCohort%canopy_layer > nclmax ) then
terminate = itrue
if ( debug ) then
write(fates_log(),*) 'terminating cohorts 2', currentCohort%canopy_layer,currentCohort%pft,call_index
endif
endif
! live biomass pools are terminally depleted
if ( ( sapw_c+leaf_c+fnrt_c ) < 1e-10_r8 .or. &
store_c < 1e-10_r8) then
terminate = itrue
if ( debug ) then
write(fates_log(),*) 'terminating cohorts 3', &
sapw_c,leaf_c,fnrt_c,store_c,currentCohort%pft,call_index
endif
endif
! Total cohort biomass is negative
if ( ( struct_c+sapw_c+leaf_c+fnrt_c+store_c ) < 0._r8) then
terminate = itrue
if ( debug ) then
write(fates_log(),*) 'terminating cohorts 4', &
struct_c,sapw_c,leaf_c,fnrt_c,store_c,currentCohort%pft,call_index
endif
endif
endif ! if (.not.currentCohort%isnew .and. level == 2) then
if (terminate == itrue) then
call terminate_cohort(currentSite, currentPatch, currentCohort, bc_in)
deallocate(currentCohort, stat=istat, errmsg=smsg)
if (istat/=0) then
write(fates_log(),*) 'dealloc001: fail on terminate_cohorts:deallocate(currentCohort):'//trim(smsg)
call endrun(msg=errMsg(sourcefile, __LINE__))
endif
endif
currentCohort => tallerCohort
enddo
end subroutine terminate_cohorts
!-------------------------------------------------------------------------------------!
subroutine terminate_cohort(currentSite, currentPatch, currentCohort, bc_in)
!
! !DESCRIPTION:
! Terminates an individual cohort and updates the site-level
! updates the carbon flux and nuber of individuals appropriately
!
! !USES:
!
! !ARGUMENTS
type (ed_site_type) , intent(inout), target :: currentSite
type (ed_patch_type) , intent(inout), target :: currentPatch
type (ed_cohort_type), intent(inout), target :: currentCohort
type(bc_in_type), intent(in) :: bc_in
! !LOCAL VARIABLES:
type (ed_cohort_type) , pointer :: shorterCohort
type (ed_cohort_type) , pointer :: tallerCohort
real(r8) :: leaf_c ! leaf carbon [kg]
real(r8) :: store_c ! storage carbon [kg]
real(r8) :: sapw_c ! sapwood carbon [kg]
real(r8) :: fnrt_c ! fineroot carbon [kg]
real(r8) :: repro_c ! reproductive carbon [kg]
real(r8) :: struct_c ! structural carbon [kg]
integer :: terminate ! do we terminate (itrue) or not (ifalse)
integer :: c ! counter for litter size class.
integer :: levcan ! canopy level
!----------------------------------------------------------------------
leaf_c = currentCohort%prt%GetState(leaf_organ, carbon12_element)
store_c = currentCohort%prt%GetState(store_organ, carbon12_element)
sapw_c = currentCohort%prt%GetState(sapw_organ, carbon12_element)
fnrt_c = currentCohort%prt%GetState(fnrt_organ, carbon12_element)
struct_c = currentCohort%prt%GetState(struct_organ, carbon12_element)
repro_c = currentCohort%prt%GetState(repro_organ, carbon12_element)
! preserve a record of the to-be-terminated cohort for mortality accounting
levcan = currentCohort%canopy_layer
if( hlm_use_planthydro == itrue ) &
call AccumulateMortalityWaterStorage(currentSite,currentCohort,currentCohort%n)
! Update the site-level carbon flux and individuals count for the appropriate canopy layer
if(levcan==ican_upper) then
currentSite%term_nindivs_canopy(currentCohort%size_class,currentCohort%pft) = &
currentSite%term_nindivs_canopy(currentCohort%size_class,currentCohort%pft) + currentCohort%n
currentSite%term_carbonflux_canopy(currentCohort%pft) = currentSite%term_carbonflux_canopy(currentCohort%pft) + &
currentCohort%n * (struct_c+sapw_c+leaf_c+fnrt_c+store_c+repro_c)
else
currentSite%term_nindivs_ustory(currentCohort%size_class,currentCohort%pft) = &
currentSite%term_nindivs_ustory(currentCohort%size_class,currentCohort%pft) + currentCohort%n
currentSite%term_carbonflux_ustory(currentCohort%pft) = currentSite%term_carbonflux_ustory(currentCohort%pft) + &
currentCohort%n * (struct_c+sapw_c+leaf_c+fnrt_c+store_c+repro_c)
end if
currentSite%term_abg_flux(currentCohort%size_class, currentCohort%pft) = &
currentSite%term_abg_flux(currentCohort%size_class, currentCohort%pft) + &
currentCohort%n * ( (struct_c+sapw_c+store_c) * prt_params%allom_agb_frac(currentCohort%pft) + &
leaf_c )
! put the litter from the terminated cohorts
! straight into the fragmenting pools
if (currentCohort%n.gt.0.0_r8) then
call SendCohortToLitter(currentSite,currentPatch, &
currentCohort,currentCohort%n,bc_in)
end if
! Set pointers and deallocate the current cohort from the list
shorterCohort => currentCohort%shorter
tallerCohort => currentCohort%taller
if (.not. associated(tallerCohort)) then
currentPatch%tallest => shorterCohort
if(associated(shorterCohort)) shorterCohort%taller => null()
else
tallerCohort%shorter => shorterCohort
endif
if (.not. associated(shorterCohort)) then
currentPatch%shortest => tallerCohort
if(associated(tallerCohort)) tallerCohort%shorter => null()
else
shorterCohort%taller => tallerCohort
endif
call DeallocateCohort(currentCohort)
end subroutine terminate_cohort
! =====================================================================================
subroutine SendCohortToLitter(csite,cpatch,ccohort,nplant,bc_in)
! -----------------------------------------------------------------------------------
! This routine transfers the existing mass in all pools and all elements
! on a vegetation cohort, into the litter pool.
!
! Important: (1) This IS NOT turnover, this is not a partial transfer.
! (2) This is from a select number of plants in the cohort. ie this is
! not a "whole-sale" sending of all plants to litter.
! (3) This does not affect the PER PLANT mass pools, so
! do not update any PARTEH structures.
! (4) The change in plant number density (due to death or termination)
! IS NOT handled here.
! (5) This routine is NOT used for disturbance, mostly
! because this routine assumes a cohort lands in its patch
! Whereas the disturbance scheme does NOT assume that.
! -----------------------------------------------------------------------------------
! Arguments
type (ed_site_type) , target :: csite
type (ed_patch_type) , target :: cpatch
type (ed_cohort_type) , target :: ccohort
real(r8) :: nplant ! Number (absolute)
! of plants to transfer
type(bc_in_type), intent(in) :: bc_in
type(litter_type), pointer :: litt ! Litter object for each element
type(site_fluxdiags_type),pointer :: flux_diags
real(r8) :: leaf_m ! leaf mass [kg]
real(r8) :: store_m ! storage mass [kg]
real(r8) :: sapw_m ! sapwood mass [kg]
real(r8) :: fnrt_m ! fineroot mass [kg]
real(r8) :: repro_m ! reproductive mass [kg]
real(r8) :: struct_m ! structural mass [kg]
real(r8) :: plant_dens! plant density [/m2]
real(r8) :: dcmpy_frac! fraction of mass going to each decomposability partition
integer :: el ! loop index for elements
integer :: c ! loop index for CWD
integer :: pft ! pft index of the cohort
integer :: crowndamage ! the crown damage class of the cohort
integer :: sl ! loop index for soil layers
integer :: dcmpy ! loop index for decomposability
!----------------------------------------------------------------------
pft = ccohort%pft
plant_dens = nplant/cpatch%area
call set_root_fraction(csite%rootfrac_scr, pft, csite%zi_soil, &