-
Notifications
You must be signed in to change notification settings - Fork 92
/
PRTAllometricCNPMod.F90
2563 lines (2004 loc) · 114 KB
/
PRTAllometricCNPMod.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 PRTAllometricCNPMod
! ------------------------------------------------------------------------------------
!
! This module contains all of the specific functions and types for
! Plant Allocation and Reactive Transport Extensible Hypotheses (PARTEH)
!
! Carbon-Nitrogen-Phosphorus (CNP) Prioritized Allometric Allocations
!
! Ryan Knox Aug 2018
!
! ------------------------------------------------------------------------------------
use PRTGenericMod , only : prt_global_type
use PRTGenericMod , only : prt_global
use PRTGenericMod , only : prt_vartypes
use PRTGenericMod , only : carbon12_element
use PRTGenericMod , only : nitrogen_element
use PRTGenericMod , only : phosphorus_element
use PRTGenericMod , only : max_nleafage
use PRTGenericMod , only : l2fr_min
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 : num_organ_types
use PRTGenericMod , only : prt_cnp_flex_allom_hyp
use PRTGenericMod , only : StorageNutrientTarget
use FatesAllometryMod , only : bleaf
use FatesAllometryMod , only : bsap_allom
use FatesAllometryMod , only : bfineroot
use FatesAllometryMod , only : bstore_allom
use FatesAllometryMod , only : bdead_allom
use FatesAllometryMod , only : bbgw_allom
use FatesAllometryMod , only : bagw_allom
use FatesAllometryMod , only : h_allom
use FatesAllometryMod , only : CheckIntegratedAllometries
use FatesGlobals , only : endrun => fates_endrun
use FatesGlobals , only : fates_log
use shr_log_mod , only : errMsg => shr_log_errMsg
use FatesConstantsMod , only : r8 => fates_r8
use FatesConstantsMod , only : i4 => fates_int
use FatesConstantsMod , only : calloc_abs_error
use FatesConstantsMod , only : rsnbl_math_prec
use FatesConstantsMod , only : years_per_day
use FatesConstantsMod , only : mm_per_cm
use FatesIntegratorsMod , only : RKF45
use FatesIntegratorsMod , only : Euler
use FatesConstantsMod , only : calloc_abs_error
use FatesConstantsMod , only : nearzero
use FatesConstantsMod , only : itrue
use FatesConstantsMod , only : fates_unset_r8
use FatesConstantsMod , only : fates_unset_int
use FatesConstantsMod , only : sec_per_day
use FatesConstantsMod , only : TRS_regeneration
use FatesConstantsMod , only : default_regeneration
use FatesConstantsMod , only : TRS_no_seedling_dyn
use FatesConstantsMod , only : min_max_dbh_for_trees
use PRTParametersMod , only : prt_params
use FatesConstantsMod , only : leaves_on,leaves_off
use FatesConstantsMod , only : leaves_shedding
use EDParamsMod , only : p_uptake_mode
use EDParamsMod , only : n_uptake_mode
use FatesConstantsMod , only : prescribed_p_uptake
use FatesConstantsMod , only : prescribed_n_uptake
use EDPftvarcon, only : EDPftvarcon_inst
use EDParamsMod , only : regeneration_model
implicit none
private
! -------------------------------------------------------------------------------------
!
! Define the state variables for this specific hypothesis. Give them units and define
! the indices that correspond with the generic classifications of PRT variables
!
! -------------------------------------------------------------------------------------
integer, parameter :: leaf_c_id = 1 ! leaf carbon index
integer, parameter :: fnrt_c_id = 2 ! fine-root carbon index
integer, parameter :: sapw_c_id = 3 ! sapwood carbon index
integer, parameter :: store_c_id = 4 ! storage carbon index
integer, parameter :: repro_c_id = 5 ! reproductive carbon index
integer, parameter :: struct_c_id = 6 ! structural carbon index
integer, parameter :: leaf_n_id = 7
integer, parameter :: fnrt_n_id = 8
integer, parameter :: sapw_n_id = 9
integer, parameter :: store_n_id = 10
integer, parameter :: repro_n_id = 11
integer, parameter :: struct_n_id = 12
integer, parameter :: leaf_p_id = 13
integer, parameter :: fnrt_p_id = 14
integer, parameter :: sapw_p_id = 15
integer, parameter :: store_p_id = 16
integer, parameter :: repro_p_id = 17
integer, parameter :: struct_p_id = 18
! Total number of state variables
integer, parameter :: num_vars = 18
! Global identifiers for the two stoichiometry values
integer,public, parameter :: stoich_growth_min = 1 ! Flag for stoichiometry associated with
! minimum needed for growth
! This is deprecated until a reasonable hypothesis is in place (RGK)
integer,public, parameter :: stoich_max = 2 ! Flag for stoichiometry associated with
! maximum for that organ
! This is the ordered list of organs used in this module
! -------------------------------------------------------------------------------------
integer, parameter :: num_organs = 6
! Converting from local to global organ id
integer, parameter,dimension(num_organs) :: l2g_organ_list = &
[leaf_organ, fnrt_organ, sapw_organ, store_organ, repro_organ, struct_organ]
! These are local indices associated with organs and quantities
! that can be integrated (namely, growth respiration during stature growth
! and dbh)
integer, parameter :: leaf_id = 1
integer, parameter :: fnrt_id = 2
integer, parameter :: sapw_id = 3
integer, parameter :: store_id = 4
integer, parameter :: repro_id = 5
integer, parameter :: struct_id = 6
integer, parameter :: dbh_id = 7
integer, parameter :: num_intgr_vars = 7
! -------------------------------------------------------------------------------------
! Input/Output Boundary Indices (These are public, and therefore
! each boundary condition across all modules must
! have a unique name !!!!)
! They are used in the routine, and also changed in the routine before
! being passed back
! -------------------------------------------------------------------------------------
integer, public, parameter :: acnp_bc_inout_id_dbh = 1 ! Plant DBH
integer, public, parameter :: acnp_bc_inout_id_resp_excess = 2 ! Respiration of excess storage
integer, public, parameter :: acnp_bc_inout_id_l2fr = 3 ! leaf 2 fineroot scalar, this
! is dynamic with CNP
integer, public, parameter :: acnp_bc_inout_id_netdn = 4 ! Index for the net daily NH4 input BC
integer, public, parameter :: acnp_bc_inout_id_netdp = 5 ! Index for the net daily P input BC
integer, public, parameter :: acnp_bc_inout_id_cx_int = 6 ! Index for the EMA log storage ratio max(N,P)/C
integer, public, parameter :: acnp_bc_inout_id_cx0 = 7 ! Index for the previous step's log storage ratio max(N,P)/C
integer, public, parameter :: acnp_bc_inout_id_emadcxdt = 8 ! Index for the EMA log storage ratio derivative d max(NP)/C dt
integer, public, parameter :: num_bc_inout = 8
! -------------------------------------------------------------------------------------
! Input only Boundary Indices (These are public)
! -------------------------------------------------------------------------------------
integer, public, parameter :: acnp_bc_in_id_pft = 1 ! Index for the PFT input BC
integer, public, parameter :: acnp_bc_in_id_ctrim = 2 ! Index for the canopy trim function
integer, public, parameter :: acnp_bc_in_id_lstat = 3 ! phenology status logical
integer, public, parameter :: acnp_bc_in_id_netdc = 4 ! Index for the net daily C input BC
integer, public, parameter :: acnp_bc_in_id_nc_repro = 5
integer, public, parameter :: acnp_bc_in_id_pc_repro = 6
integer, public, parameter :: acnp_bc_in_id_cdamage = 7 ! Index for the crowndamage input BC
integer, public, parameter :: acnp_bc_in_id_efleaf = 8 ! Leaf elongation factor
integer, public, parameter :: acnp_bc_in_id_effnrt = 9 ! Fine-root "elongation factor"
integer, public, parameter :: acnp_bc_in_id_efstem = 10 ! Stem "elongation factor"
integer, parameter :: num_bc_in = 10
! -------------------------------------------------------------------------------------
! Output Boundary Indices (These are public)
! -------------------------------------------------------------------------------------
integer, public, parameter :: acnp_bc_out_id_cefflux = 1 ! Daily exudation of C [kg]
integer, public, parameter :: acnp_bc_out_id_nefflux = 2 ! Daily exudation of N [kg]
integer, public, parameter :: acnp_bc_out_id_pefflux = 3 ! Daily exudation of P [kg]
integer, public, parameter :: acnp_bc_out_id_limiter = 4 ! The minimum of the Nutrient ratio over c ratio
integer, parameter :: num_bc_out = 4 ! Total number of
! Indices for parameters passed to the integrator
integer,private, parameter :: intgr_parm_ctrim = 1
integer,private, parameter :: intgr_parm_pft = 2
integer,private, parameter :: intgr_parm_l2fr = 3
integer,private, parameter :: intgr_parm_cdamage = 4
integer,private, parameter :: intgr_parm_efleaf = 5
integer,private, parameter :: intgr_parm_effnrt = 6
integer,private, parameter :: intgr_parm_efstem = 7
integer,private, parameter :: num_intgr_parm = 7
! -------------------------------------------------------------------------------------
! Define the size of the coorindate vector. For this hypothesis, there is only
! one pool per each species x organ combination, except for leaves (WHICH HAVE AGE)
! icd refers to the first index in the leaf array, which is the youngest. Growth
! and allocation only happens in the youngest bin by definition
! -------------------------------------------------------------------------------------
integer, parameter :: icd = 1
! These constants define different methods of dealing with excess carbon at
! the end of the allocation process, assuming that N or P is limiting growth.
! You can either exude (send to soil), retain (grow storage without limit),
! or burn (as respiration to the atm).
integer, parameter :: exude_c_store_overflow = 1
integer, parameter :: retain_c_store_overflow = 2
integer, parameter :: burn_c_store_overflow = 3
integer, parameter :: store_c_overflow = burn_c_store_overflow
! These constants define if/how growth is limited by
! one of the 3 chemical species, 0 indicates there is some
! degree of co limitation
integer, parameter :: cnp_limited = 0
integer, parameter :: c_limited = 1
integer, parameter :: n_limited = 2
integer, parameter :: p_limited = 3
! Flags to select using the equivalent carbon method of co-limitation,
! or to just grow with available carbon and let it fix itself on the
! next step
integer, parameter :: grow_lim_conly = 1 ! Just use C to decide stature on this step
integer, parameter :: grow_lim_estNP = 2 ! Estimate equivalent C from N and P
integer, parameter :: grow_lim_type = grow_lim_estNP
! Following growth, if desired, you can prioritize that
! reproductive tissues get balanced CNP
logical, parameter :: prioritize_repro_nutr_growth = .true.
! If this parameter is true, then the fine-root l2fr optimization
! scheme will remove biomass from roots without restriction if the
! l2fr is getting smaller.
logical, parameter :: use_unrestricted_contraction = .true.
! -------------------------------------------------------------------------------------
! This is the core type that holds this specific
! plant reactive transport (PRT) module
! -------------------------------------------------------------------------------------
type, public, extends(prt_vartypes) :: cnp_allom_prt_vartypes
contains
procedure :: DailyPRT => DailyPRTAllometricCNP
procedure :: FastPRT => FastPRTAllometricCNP
procedure :: GetNutrientTarget => GetNutrientTargetCNP
! Extended functions specific to Allometric CNP
procedure :: CNPPrioritizedReplacement
procedure :: CNPStatureGrowth
procedure :: EstimateGrowthNC
procedure :: CNPAdjustFRootTargets
procedure :: CNPAllocateRemainder
procedure :: GetDeficit
procedure :: TrimFineRoot
end type cnp_allom_prt_vartypes
! ------------------------------------------------------------------------------------
!
! This next class is an extention of the base instance that maps state variables
! to the outside model.
!
! This is the instance of the mapping table and variable definitions
! this is only allocated once per node
! ------------------------------------------------------------------------------------
class(prt_global_type), public, target, allocatable :: prt_global_acnp
character(len=*), parameter, private :: sourcefile = __FILE__
logical, parameter :: debug = .false.
public :: InitPRTGlobalAllometricCNP
contains
subroutine InitPRTGlobalAllometricCNP()
! ----------------------------------------------------------------------------------
! Initialize and populate the general mapping table that
! organizes the specific variables in this module to
! pre-ordained groups, so they can be used to inform
! the rest of the model
!
! This routine is not part of the sp_pool_vartypes class
! because it is the same for all plants and we need not
! waste memory on it.
! -----------------------------------------------------------------------------------
integer :: nleafage
integer :: istat
character(len=255) :: smsg
allocate(prt_global_acnp, stat=istat, errmsg=smsg)
if (istat/=0) call endrun(msg='allocate stat/=0:'//trim(smsg)//errMsg(sourcefile, __LINE__))
allocate(prt_global_acnp%state_descriptor(num_vars), stat=istat, errmsg=smsg)
if (istat/=0) call endrun(msg='allocate stat/=0:'//trim(smsg)//errMsg(sourcefile, __LINE__))
prt_global_acnp%hyp_name = 'Allometric Flexible C+N+P'
prt_global_acnp%hyp_id = prt_cnp_flex_allom_hyp
call prt_global_acnp%ZeroGlobal()
! The number of leaf age classes can be determined from the parameter file,
! notably the size of the leaf-longevity parameter's second dimension.
! This is the same value in FatesInterfaceMod.F90
nleafage = size(prt_params%leaf_long,dim=2)
if(nleafage>max_nleafage) then
write(fates_log(),*) 'The allometric carbon PARTEH hypothesis'
write(fates_log(),*) 'sets a maximum number of leaf age classes'
write(fates_log(),*) 'used for scratch space. The model wants'
write(fates_log(),*) 'exceed that. Simply increase max_nleafage'
write(fates_log(),*) 'found in parteh/PRTAllometricCarbonMod.F90'
call endrun(msg=errMsg(sourcefile, __LINE__))
end if
call prt_global_acnp%RegisterVarInGlobal(leaf_c_id,'Leaf Carbon','leaf_c',leaf_organ,carbon12_element,nleafage)
call prt_global_acnp%RegisterVarInGlobal(fnrt_c_id,'Fine Root Carbon','fnrt_c',fnrt_organ,carbon12_element,icd)
call prt_global_acnp%RegisterVarInGlobal(sapw_c_id,'Sapwood Carbon','sapw_c',sapw_organ,carbon12_element,icd)
call prt_global_acnp%RegisterVarInGlobal(store_c_id,'Storage Carbon','store_c',store_organ,carbon12_element,icd)
call prt_global_acnp%RegisterVarInGlobal(struct_c_id,'Structural Carbon','struct_c',struct_organ,carbon12_element,icd)
call prt_global_acnp%RegisterVarInGlobal(repro_c_id,'Reproductive Carbon','repro_c',repro_organ,carbon12_element,icd)
call prt_global_acnp%RegisterVarInGlobal(leaf_n_id,'Leaf Nitrogen','leaf_n',leaf_organ,nitrogen_element,nleafage)
call prt_global_acnp%RegisterVarInGlobal(fnrt_n_id,'Fine Root Nitrogen','fnrt_n',fnrt_organ,nitrogen_element,icd)
call prt_global_acnp%RegisterVarInGlobal(sapw_n_id,'Sapwood Nitrogen','sapw_n',sapw_organ,nitrogen_element,icd)
call prt_global_acnp%RegisterVarInGlobal(store_n_id,'Storage Nitrogen','store_n',store_organ,nitrogen_element,icd)
call prt_global_acnp%RegisterVarInGlobal(struct_n_id,'Structural Nitrogen','struct_n',struct_organ,nitrogen_element,icd)
call prt_global_acnp%RegisterVarInGlobal(repro_n_id,'Reproductive Nitrogen','repro_n',repro_organ,nitrogen_element,icd)
call prt_global_acnp%RegisterVarInGlobal(leaf_p_id,'Leaf Phosphorus','leaf_p',leaf_organ,phosphorus_element,nleafage)
call prt_global_acnp%RegisterVarInGlobal(fnrt_p_id,'Fine Root Phosphorus','fnrt_p',fnrt_organ,phosphorus_element,icd)
call prt_global_acnp%RegisterVarInGlobal(sapw_p_id,'Sapwood Phosphorus','sapw_p',sapw_organ,phosphorus_element,icd)
call prt_global_acnp%RegisterVarInGlobal(store_p_id,'Storage Phosphorus','store_p',store_organ,phosphorus_element,icd)
call prt_global_acnp%RegisterVarInGlobal(struct_p_id,'Structural Phosphorus','struct_p',struct_organ,phosphorus_element,icd)
call prt_global_acnp%RegisterVarInGlobal(repro_p_id,'Reproductive Phosphorus','repro_p',repro_organ,phosphorus_element,icd)
! Set some of the array sizes for input and output boundary conditions
prt_global_acnp%num_bc_in = num_bc_in
prt_global_acnp%num_bc_out = num_bc_out
prt_global_acnp%num_bc_inout = num_bc_inout
prt_global_acnp%num_vars = num_vars
! Have the global generic pointer, point to this hypothesis' object
prt_global => prt_global_acnp
return
end subroutine InitPRTGlobalAllometricCNP
! =====================================================================================
subroutine DailyPRTAllometricCNP(this,phase)
class(cnp_allom_prt_vartypes) :: this
integer,intent(in) :: phase ! the phase splits the routine into parts
! note that phasing is used primarily to
! accomodate the damage module. Damage
! and nutrient cycling are not yet compatable though
! hence, we simply return from any phase but phase 1
! Pointers to in-out bcs
real(r8),pointer :: dbh ! Diameter at breast height [cm]
real(r8),pointer :: resp_excess ! Respiration of any un-allocatable C
real(r8),pointer :: l2fr ! Leaf to fineroot ratio of target biomass
! Input only bcs
integer :: ipft ! Plant Functional Type index
real(r8) :: c_gain ! Daily carbon balance for this cohort [kgC]
real(r8),pointer :: n_gain ! Daily nitrogen uptake through fine-roots [kgN]
real(r8),pointer :: p_gain ! Daily phosphorus uptake through fine-roots [kgN]
real(r8) :: canopy_trim ! The canopy trimming function [0-1]
integer :: crown_damage ! which crown damage clas
real(r8) :: elongf_leaf ! Leaf elongation factor [0-1]
real(r8) :: elongf_fnrt ! Fine-root "elongation factor" [0-1]
real(r8) :: elongf_stem ! Stem "elongation factor" [0-1]
! Pointers to output bcs
real(r8),pointer :: c_efflux ! Total plant efflux of carbon (kgC)
real(r8),pointer :: n_efflux ! Total plant efflux of nitrogen (kgN)
real(r8),pointer :: p_efflux ! Total plant efflux of phosphorus (kgP)
! Allometry targets (kg/plant) and (kg/cm/plant)
real(r8), dimension(num_organ_types) :: target_c, target_dcdd
! Initial states (for accounting) (kg/plant)
real(r8), dimension(num_organ_types) :: state_c0, state_n0, state_p0
! Allometry partial targets
real(r8) :: agw_c_target,agw_dcdd_target
real(r8) :: bgw_c_target,bgw_dcdd_target
real(r8) :: sapw_area
real(r8) :: store_flux
integer :: i ! generic organ loop index
integer :: i_org ! organ index
integer :: i_var ! variable index
! These are daily mass gains, frozen in time, not drawn from, and thus
! these are only used for evaluating mass balancing at the end
real(r8) :: dbh0
real(r8) :: c_gain0
real(r8) :: n_gain0
real(r8) :: p_gain0
real(r8) :: resp_excess0
! Used for mass checking, total mass allocated based
! on change in the states, should match gain0's
real(r8) :: allocated_c
real(r8) :: allocated_n
real(r8) :: allocated_p
real(r8) :: sum_c ! error checking sum
! Phasing is only used to accomodate the
! damage module. Since this is incompatible with CNP
! Ignore all subsequent calls after the first
if (phase.ne.1) return
! In/out boundary conditions
resp_excess => this%bc_inout(acnp_bc_inout_id_resp_excess)%rval
dbh => this%bc_inout(acnp_bc_inout_id_dbh)%rval
dbh0 = dbh
l2fr => this%bc_inout(acnp_bc_inout_id_l2fr)%rval
n_gain => this%bc_inout(acnp_bc_inout_id_netdn)%rval
p_gain => this%bc_inout(acnp_bc_inout_id_netdp)%rval
! Assume that there is no other source of excess respiration
! so it is safe to zero it. In the third stage we will
! decide if this should be updated
resp_excess = 0._r8
resp_excess0 = resp_excess
! integrator variables
! Copy the input only boundary conditions into readable local variables
! We don't use pointers, because inputs should be intent in only
! Also, we save the initial values of many of these BC's
! for checking and resetting if needed
! -----------------------------------------------------------------------------------
c_gain = this%bc_in(acnp_bc_in_id_netdc)%rval
canopy_trim = this%bc_in(acnp_bc_in_id_ctrim)%rval
ipft = this%bc_in(acnp_bc_in_id_pft)%ival
crown_damage = this%bc_in(acnp_bc_in_id_cdamage)%ival
elongf_leaf = this%bc_in(acnp_bc_in_id_efleaf)%rval
elongf_fnrt = this%bc_in(acnp_bc_in_id_effnrt)%rval
elongf_stem = this%bc_in(acnp_bc_in_id_efstem)%rval
! If either n or p uptake is in prescribed mode
! set the gains to something massive. 1 kilo of pure
! nutrient should be wayyy more than enough
if(n_uptake_mode.eq.prescribed_n_uptake) then
n_gain = 1.e3_r8
end if
if(p_uptake_mode.eq.prescribed_p_uptake) then
p_gain = 1.e3_r8
end if
n_gain0 = n_gain
p_gain0 = p_gain
c_gain0 = c_gain
! Calculate Carbon allocation targets
! -----------------------------------------------------------------------------------
! Set carbon targets based on the plant's current stature
target_c(:) = fates_unset_r8
target_dcdd(:) = fates_unset_r8
call bsap_allom(dbh,ipft,crown_damage,canopy_trim,elongf_stem,sapw_area,target_c(sapw_organ),target_dcdd(sapw_organ))
call bagw_allom(dbh,ipft,crown_damage,elongf_stem,agw_c_target,agw_dcdd_target)
call bbgw_allom(dbh,ipft,elongf_stem,bgw_c_target,bgw_dcdd_target)
call bdead_allom(agw_c_target,bgw_c_target,target_c(sapw_organ),ipft,target_c(struct_organ), &
agw_dcdd_target,bgw_dcdd_target,target_dcdd(sapw_organ),target_dcdd(struct_organ))
call bleaf(dbh,ipft,crown_damage,canopy_trim, elongf_leaf, target_c(leaf_organ), target_dcdd(leaf_organ))
call bfineroot(dbh,ipft,canopy_trim, l2fr, elongf_fnrt, target_c(fnrt_organ), target_dcdd(fnrt_organ))
call bstore_allom(dbh,ipft,crown_damage, canopy_trim, target_c(store_organ), target_dcdd(store_organ))
target_c(repro_organ) = 0._r8
target_dcdd(repro_organ) = 0._r8
! ===================================================================================
! Step 1: Evaluate nutrient storage in the plant. Depending on how low
! these stores are, we will move proportionally more or less of the daily carbon
! gain to increase the target fine-root biomass, fill up to target
! and then attempt to get them up to stoichiometry targets.
! ===================================================================================
! Remember the original C,N,P states to help with final
! evaluation of how much was allocated
! -----------------------------------------------------------------------------------
do i = 1,num_organs
i_org = l2g_organ_list(i) ! global index from PRTGeneric
i_var = prt_global%sp_organ_map(i_org,carbon12_element)
state_c0(i_org) = this%variables(i_var)%val(1)
i_var = prt_global%sp_organ_map(i_org,nitrogen_element)
state_n0(i_org) = this%variables(i_var)%val(1)
i_var = prt_global%sp_organ_map(i_org,phosphorus_element)
state_p0(i_org) = this%variables(i_var)%val(1)
end do
! Output only boundary conditions
c_efflux => this%bc_out(acnp_bc_out_id_cefflux)%rval; c_efflux = 0._r8
n_efflux => this%bc_out(acnp_bc_out_id_nefflux)%rval; n_efflux = 0._r8
p_efflux => this%bc_out(acnp_bc_out_id_pefflux)%rval; p_efflux = 0._r8
! ===================================================================================
! Step 0. Transfer all stored nutrient into the daily uptake pool. Also
! transfer C storage that is above the target (ie transfer overflow)
! ===================================================================================
! Put overflow storage into the net daily pool
store_flux = max(0._r8, this%variables(store_c_id)%val(1) - target_c(store_organ))
c_gain = c_gain + store_flux
this%variables(store_c_id)%val(1) = this%variables(store_c_id)%val(1) - store_flux
n_gain = n_gain + sum(this%variables(store_n_id)%val(:))
this%variables(store_n_id)%val(:) = 0._r8
p_gain = p_gain + sum(this%variables(store_p_id)%val(:))
this%variables(store_p_id)%val(:) = 0._r8
! ===================================================================================
! Step 2. Prioritized allocation to replace tissues from turnover, and/or pay
! any un-paid maintenance respiration from storage.
! ===================================================================================
call this%CNPPrioritizedReplacement(c_gain, n_gain, p_gain, target_c)
sum_c = 0._r8
do i = 1,num_organs
i_org = l2g_organ_list(i)
i_var = prt_global%sp_organ_map(i_org,carbon12_element)
sum_c = sum_c+this%variables(i_var)%val(1)
end do
if( abs((c_gain0-c_gain) - &
(sum_c-sum(state_c0(:),dim=1))) >calloc_abs_error ) then
write(fates_log(),*) 'Carbon not balancing I'
do i = 1,num_organs
i_org = l2g_organ_list(i)
write(fates_log(),*) 'c: ',this%variables(prt_global%sp_organ_map(i_org,carbon12_element))%val(1)
end do
call endrun(msg=errMsg(sourcefile, __LINE__))
end if
! ===================================================================================
! Step 3. Grow out the stature of the plant by allocating to tissues beyond
! current targets.
! Attempts have been made to get all pools and species closest to allometric
! targets based on prioritized relative demand and allometry functions.
! ===================================================================================
call this%CNPStatureGrowth(c_gain, n_gain, p_gain, target_c, target_dcdd)
sum_c = 0._r8
do i = 1,num_organs
i_org = l2g_organ_list(i)
i_var = prt_global%sp_organ_map(i_org,carbon12_element)
sum_c = sum_c+this%variables(i_var)%val(1)
end do
if( abs((c_gain0-c_gain) - &
(sum_c-sum(state_c0(:),dim=1))) >calloc_abs_error ) then
write(fates_log(),*) 'Carbon not balancing II'
do i = 1,num_organs
i_org = l2g_organ_list(i)
write(fates_log(),*) 'c: ',this%variables(prt_global%sp_organ_map(i_org,carbon12_element))%val(1)
end do
call endrun(msg=errMsg(sourcefile, __LINE__))
end if
! ===================================================================================
! Step 3.
! At this point, at least 1 of the 3 resources have been used up.
! Allocate the remaining resources, or as a last resort, efflux them.
! ===================================================================================
call this%CNPAllocateRemainder(c_gain, n_gain, p_gain, &
c_efflux, n_efflux, p_efflux,target_c,target_dcdd)
if(n_uptake_mode.ne.prescribed_n_uptake) then
if( abs(n_gain) > 0.1_r8*calloc_abs_error) then
write(fates_log(),*) 'Allocation scheme should had used up all mass gain pools'
write(fates_log(),*) 'Any mass that cannot be allocated should be effluxed'
write(fates_log(),*) 'n_gain: ',n_gain
call endrun(msg=errMsg(sourcefile, __LINE__))
end if
end if
if(p_uptake_mode.ne.prescribed_p_uptake) then
if( abs(p_gain) > 0.01_r8*calloc_abs_error) then
write(fates_log(),*) 'Allocation scheme should had used up all mass gain pools'
write(fates_log(),*) 'Any mass that cannot be allocated should be effluxed'
write(fates_log(),*) 'p_gain: ',p_gain
call endrun(msg=errMsg(sourcefile, __LINE__))
end if
end if
if( abs(c_gain) > calloc_abs_error) then
write(fates_log(),*) 'Allocation scheme should had used up all mass gain pools'
write(fates_log(),*) 'Any mass that cannot be allocated should be effluxed'
write(fates_log(),*) 'c_gain: ',c_gain
call endrun(msg=errMsg(sourcefile, __LINE__))
end if
! Perform a final tally on what was used (allocated)
! Since this is also a check against what was available
! we include what is lost through respiration of excess storage
allocated_c = (resp_excess-resp_excess0) + c_efflux
allocated_n = n_efflux
allocated_p = p_efflux
! Update the allocation flux diagnostic arrays for each 3 elements
do i = 1,num_organs
i_org = l2g_organ_list(i)
i_var = prt_global%sp_organ_map(i_org,carbon12_element)
this%variables(i_var)%net_alloc(1) = &
this%variables(i_var)%net_alloc(1) + (this%variables(i_var)%val(1) - state_c0(i_org))
allocated_c = allocated_c + (this%variables(i_var)%val(1) - state_c0(i_org))
i_var = prt_global%sp_organ_map(i_org,nitrogen_element)
this%variables(i_var)%net_alloc(1) = &
this%variables(i_var)%net_alloc(1) + (this%variables(i_var)%val(1) - state_n0(i_org))
allocated_n = allocated_n + (this%variables(i_var)%val(1) - state_n0(i_org))
i_var = prt_global%sp_organ_map(i_org,phosphorus_element)
this%variables(i_var)%net_alloc(1) = &
this%variables(i_var)%net_alloc(1) + (this%variables(i_var)%val(1) - state_p0(i_org))
allocated_p = allocated_p + (this%variables(i_var)%val(1) - state_p0(i_org))
end do
if(debug) then
! Error Check: Do a final balance between how much mass
! we had to work with, and how much was allocated
if ( abs(allocated_c - (c_gain0-c_gain)) > calloc_abs_error .or. &
abs(allocated_n - (n_gain0-n_gain)) > calloc_abs_error .or. &
abs(allocated_p - (p_gain0-p_gain)) > calloc_abs_error ) then
write(fates_log(),*) 'CNP allocation scheme did not balance mass.'
write(fates_log(),*) 'c_gain0: ',c_gain0,' allocated_c: ',allocated_c,resp_excess,resp_excess0,c_efflux
write(fates_log(),*) 'n_gain0: ',n_gain0,' allocated_n: ',allocated_n
write(fates_log(),*) 'p_gain0: ',p_gain0,' allocated_p: ',allocated_p
do i = 1,num_organs
i_org = l2g_organ_list(i)
i_var = prt_global%sp_organ_map(i_org,carbon12_element)
write(fates_log(),*) i_org, this%variables(i_var)%val(1)-state_c0(i_org)
end do
call endrun(msg=errMsg(sourcefile, __LINE__))
end if
end if
! IF this was prescribed, then we dictate the uptake
! and pass that back as an output, otherwise
! we set the gains to what we started with so that
! it can be used again for mass balance checking and diagnostics
if(n_uptake_mode.eq.prescribed_n_uptake) then
n_gain = n_gain0-n_gain
else
n_gain = n_gain0
end if
if(p_uptake_mode.eq.prescribed_p_uptake) then
p_gain = p_gain0-p_gain
else
p_gain = p_gain0
end if
! If fine-roots are allocated above their
! target (perhaps with some buffer, but perhaps not)
! then
call this%TrimFineRoot()
return
end subroutine DailyPRTAllometricCNP
function SafeLog(val) result(logval)
! The log functions used to transform storage ratios
! need not be large. Even a ratio of 10 is sending a strong signal to the
! root adaptation algorithm to change course pretty strongly. We set
! bounds of e3 here to prevent numerical overflows and underflows
real(r8) :: val
real(r8) :: logval
real(r8), parameter :: safelog_min = 0.001_r8 !Don't pass anything smaller to a log
real(r8), parameter :: safelog_max = 1000._r8
logval = log(max(safelog_min,min(safelog_max,val)))
end function SafeLog
! =====================================================================================
subroutine CNPAdjustFRootTargets(this, target_c, target_dcdd)
class(cnp_allom_prt_vartypes) :: this
real(r8) :: target_c(:)
real(r8) :: target_dcdd(:)
real(r8), pointer :: l2fr ! leaf to fineroot target biomass scaler
integer :: ipft ! PFT index
real(r8), pointer :: dbh
real(r8) :: canopy_trim
integer :: leaf_status
integer, pointer :: limiter
real(r8) :: elongf_fnrt
real(r8) :: store_c_max, store_c_act
real(r8) :: store_nut_max, store_nut_act
real(r8) :: l2fr_delta
real(r8) :: cn_ratio, cp_ratio ! ratio of relative C storage over relative N or P storage
real(r8) :: dcxdt_ratio ! log change (derivative) of the maximum of the N/C and P/C storage ratio
real(r8) :: cx_logratio ! log Maximum of the C/N and C/P storage ratio
real(r8), pointer :: cx_int ! Integration of the cx_logratio
real(r8), pointer :: cx0 ! The log of the cx ratio from previous time-step
real(r8), pointer :: ema_dcxdt ! the EMA of the change in log storage ratio
real(r8), parameter :: pid_drv_wgt = 1._r8/20._r8 ! n-day smoothing of the derivative
! of the process function in the PID controller
leaf_status = this%bc_in(acnp_bc_in_id_lstat)%ival
ipft = this%bc_in(acnp_bc_in_id_pft)%ival
elongf_fnrt = this%bc_in(acnp_bc_in_id_effnrt)%rval
l2fr => this%bc_inout(acnp_bc_inout_id_l2fr)%rval
dbh => this%bc_inout(acnp_bc_inout_id_dbh)%rval
canopy_trim = this%bc_in(acnp_bc_in_id_ctrim)%rval
cx_int => this%bc_inout(acnp_bc_inout_id_cx_int)%rval
cx0 => this%bc_inout(acnp_bc_inout_id_cx0)%rval
ema_dcxdt => this%bc_inout(acnp_bc_inout_id_emadcxdt)%rval
limiter => this%bc_out(acnp_bc_out_id_limiter)%ival
! Abort if leaves are off
if(leaf_status.eq.leaves_off) return
! Step 1: Determine the process function for the controller. Generally, this is
! some indicator about the relative health of the plant in terms of carbon versus
! nutrient. There are a few ways to cast this function, but right now we are using
! the relative amount of Carbon storage (actual/maximum) divided by the relative amount
! of nutrient (actual/maximum). We take the natural log of this ratio. And then we take
! maximum of the two quotients that use nitrogen and phosphorus.
! -----------------------------------------------------------------------------------
store_c_max = target_c(store_organ)
store_c_act = max(0.001_r8*store_c_max,this%GetState(store_organ, carbon12_element) + &
this%bc_in(acnp_bc_in_id_netdc)%rval)
if(n_uptake_mode.eq.prescribed_n_uptake)then
cn_ratio = -1._r8
else
! Calculate the relative nitrogen storage fraction,
! over the relative carbon storage fraction.
store_nut_max = this%GetNutrientTarget(nitrogen_element,store_organ,stoich_growth_min)
store_nut_act = max(0.001_r8*store_nut_max, &
this%GetState(store_organ, nitrogen_element) + &
this%bc_inout(acnp_bc_inout_id_netdn)%rval)
cn_ratio = (store_c_act/store_c_max)/(store_nut_act/store_nut_max)
end if
if(p_uptake_mode.eq.prescribed_p_uptake)then
cp_ratio = -1._r8
else
! Calculate the relative phosphorus storage fraction,
! over the relative carbon storage fraction.
store_nut_max = this%GetNutrientTarget(phosphorus_element,store_organ,stoich_growth_min)
store_nut_act = max(0.001_r8*store_nut_max, &
this%GetState(store_organ, phosphorus_element) + &
this%bc_inout(acnp_bc_inout_id_netdp)%rval)
cp_ratio = (store_c_act/store_c_max)/(store_nut_act/store_nut_max)
end if
! Use the limiting nutrient species
if( (n_uptake_mode.eq.prescribed_n_uptake) .and. &
(p_uptake_mode.eq.prescribed_p_uptake) )then
cx_int = 0._r8
ema_dcxdt = 0._r8
cx0 = 0.0_r8
return
else
if (n_uptake_mode.eq.prescribed_n_uptake) then
cx_logratio = SafeLog(cp_ratio)
elseif (p_uptake_mode.eq.prescribed_p_uptake) then
cx_logratio = SafeLog(cn_ratio)
else
cx_logratio = SafeLog(max(cp_ratio,cn_ratio))
end if
! If cx_logratio has just crossed zero, then
! reset the integrator. This will be true if
! the sign of the current ratio is different than
! the sign of the previous
cx_int = cx_int + cx_logratio
! Reset the integrator if its sign changes
if( abs(cx_logratio)>nearzero .and. abs(cx0)>nearzero) then
if( abs(cx_logratio/abs(cx_logratio) - cx0/abs(cx0)) > nearzero ) then
cx_int = cx_logratio
end if
end if
dcxdt_ratio = cx_logratio-cx0
ema_dcxdt = pid_drv_wgt*dcxdt_ratio + (1._r8-pid_drv_wgt)*ema_dcxdt
cx0 = cx_logratio
end if
l2fr_delta = prt_params%pid_kp(ipft)*cx_logratio + &
prt_params%pid_ki(ipft)*cx_int + &
prt_params%pid_kd(ipft)*ema_dcxdt
! Apply the delta, also, avoid generating incredibly small l2fr's,
! super small l2frs will occur in plants that perpetually get almost
! now carbon gain, such as newly recruited plants in a dark understory
l2fr = max(l2fr_min, l2fr + l2fr_delta)
! Find the updated target fineroot biomass
call bfineroot(dbh,ipft,canopy_trim, l2fr, elongf_fnrt, target_c(fnrt_organ),target_dcdd(fnrt_organ))
return
end subroutine CNPAdjustFRootTargets
! =====================================================================================
subroutine TrimFineRoot(this)
! The following section allows forceful turnover of fine-roots if a new L2FR is generated
! that is lower than the previous l2fr. The maintenance turnover (background) rate
! will automatically accomodate a lower l2fr, but if the change is large it will
! not keep pace. Note 1: however, that the algorithm for calculating l2fr will prevent
! large drops in l2fr (unless that safegaurd is removed). Note 2: this section may also
! generate mass check errors in the main CNPAllocation routine, this is because the "val" is
! changing but the net_allocated is not reciprocating, which is expected.
! Keep a buffer above the L2FR in the hopes that natural turnover will catch
! up.
class(cnp_allom_prt_vartypes) :: this
real(r8) :: fnrt_flux_c
real(r8) :: turn_flux_c
real(r8) :: store_flux_c
real(r8) :: nc_fnrt
real(r8) :: pc_fnrt
real(r8) :: target_fnrt_c
real(r8),parameter :: nday_buffer = 0._r8
real(r8),parameter :: fnrt_opt_eff = 0._r8 ! If we want to transfer resources to storage
if(.not.use_unrestricted_contraction)return
associate( ipft => this%bc_in(acnp_bc_in_id_pft)%ival, &
l2fr => this%bc_inout(acnp_bc_inout_id_l2fr)%rval, &
dbh => this%bc_inout(acnp_bc_inout_id_dbh)%rval, &
elongf_fnrt => this%bc_in(acnp_bc_in_id_effnrt)%rval, &
canopy_trim => this%bc_in(acnp_bc_in_id_ctrim)%rval)
! Find the updated target fineroot biomass
call bfineroot(dbh,ipft,canopy_trim, l2fr, elongf_fnrt, target_fnrt_c)
fnrt_flux_c = max(0._r8,this%variables(fnrt_c_id)%val(1)*(1._r8-nday_buffer*(years_per_day / prt_params%root_long(ipft))) - target_fnrt_c )
if(fnrt_flux_c>nearzero) then
turn_flux_c = (1._r8 - fnrt_opt_eff)*fnrt_flux_c
store_flux_c = fnrt_opt_eff*fnrt_flux_c
nc_fnrt = this%variables(fnrt_n_id)%val(1)/this%variables(fnrt_c_id)%val(1)
pc_fnrt = this%variables(fnrt_p_id)%val(1)/this%variables(fnrt_c_id)%val(1)
this%variables(fnrt_c_id)%val(1) = this%variables(fnrt_c_id)%val(1) - fnrt_flux_c
this%variables(fnrt_c_id)%turnover(1) = this%variables(fnrt_c_id)%turnover(1) + turn_flux_c
this%variables(fnrt_c_id)%net_alloc(1) = this%variables(fnrt_c_id)%net_alloc(1) - store_flux_c
this%variables(store_c_id)%val(1) = this%variables(store_c_id)%val(1) + store_flux_c
this%variables(store_c_id)%net_alloc(1) = this%variables(store_c_id)%net_alloc(1) + store_flux_c
this%variables(fnrt_n_id)%val(1) = this%variables(fnrt_n_id)%val(1) - fnrt_flux_c * nc_fnrt
this%variables(fnrt_n_id)%turnover(1) = this%variables(fnrt_n_id)%turnover(1) + turn_flux_c * nc_fnrt
this%variables(fnrt_n_id)%net_alloc(1) = this%variables(fnrt_n_id)%net_alloc(1) - store_flux_c * nc_fnrt
this%variables(store_n_id)%val(1) = this%variables(store_n_id)%val(1) + store_flux_c * nc_fnrt
this%variables(store_n_id)%net_alloc(1) = this%variables(store_n_id)%net_alloc(1) + store_flux_c * nc_fnrt
this%variables(fnrt_p_id)%val(1) = this%variables(fnrt_p_id)%val(1) - fnrt_flux_c * pc_fnrt
this%variables(fnrt_p_id)%turnover(1) = this%variables(fnrt_p_id)%turnover(1) + turn_flux_c * pc_fnrt
this%variables(fnrt_p_id)%net_alloc(1) = this%variables(fnrt_p_id)%net_alloc(1) - store_flux_c * pc_fnrt
this%variables(store_p_id)%val(1) = this%variables(store_p_id)%val(1) + store_flux_c * pc_fnrt
this%variables(store_p_id)%net_alloc(1) = this%variables(store_p_id)%net_alloc(1) + store_flux_c * pc_fnrt
end if
end associate
return
end subroutine TrimFineRoot
! =====================================================================================
subroutine CNPPrioritizedReplacement(this,c_gain, n_gain, p_gain, target_c)
! -----------------------------------------------------------------------------------
! Alternative allocation hypothesis for the prioritized replacement phase.
! This is more similar to the current (04/2020) carbon only hypothesis.
! -----------------------------------------------------------------------------------
class(cnp_allom_prt_vartypes) :: this
real(r8), intent(inout) :: c_gain
real(r8), intent(inout) :: n_gain
real(r8), intent(inout) :: p_gain
real(r8), intent(in) :: target_c(:) ! Indexed by global organ (from PRTGenericMod)
integer :: n_curpri_org
integer, dimension(num_organs) :: curpri_org ! organ ID's of the current priority level
real(r8), dimension(num_organs) :: deficit_c ! Deficit to get to target from current [kg]
real(r8), dimension(num_organs) :: deficit_n ! Deficit to get to target from current [kg]
real(r8), dimension(num_organs) :: deficit_p ! Deficit to get to target from current [kg]
integer :: i, ii, i_org ! Loop indices (mostly for organs)
integer :: i_var ! variable index
integer :: i_pri ! loop index for priority
integer :: ipft ! Plant functional type index of this plant
integer :: leaf_status ! Is this plant in a leaf on or off status?
real(r8) :: canopy_trim ! trim factor for maximum leaf biomass
real(r8) :: target_n ! Target mass of N for a given organ [kg]
real(r8) :: target_p ! Target mass of P for a given organ [kg]
real(r8) :: elongf_leaf ! Leaf elongation factor
real(r8) :: elongf_fnrt ! Fine-root "elongation factor"
real(r8) :: elongf_stem ! Stem "elongation factor"
integer :: priority_code ! Index for priority level of each organ
real(r8) :: sum_c_demand ! Carbon demanded to bring tissues up to allometry (kg)
real(r8) :: store_below_target ! The amount of storage that is less than the target (kg)
real(r8) :: store_target_fraction ! The fraction of actual storage carbon over the target (kg)
real(r8) :: store_demand ! Based on the target fraction, an exponential function defining
! how much carbon we should try to put back into storage
real(r8) :: store_c_flux ! The amount of C we draw from gains to give back to storage (kg)
real(r8) :: sum_c_flux ! The flux to bring tissues up to allometry (kg)
real(r8) :: c_flux ! carbon flux into an arbitrary pool (kg)
integer :: n_max_priority ! Maximum possible number of priority levels is
! the total number organs plus 1, which allows
! each organ to have its own level, and ignore
! the specialized priority 1
leaf_status = this%bc_in(acnp_bc_in_id_lstat)%ival
elongf_leaf = this%bc_in(acnp_bc_in_id_efleaf)%rval
elongf_fnrt = this%bc_in(acnp_bc_in_id_effnrt)%rval
elongf_stem = this%bc_in(acnp_bc_in_id_efstem)%rval
ipft = this%bc_in(acnp_bc_in_id_pft)%ival
canopy_trim = this%bc_in(acnp_bc_in_id_ctrim)%rval
n_max_priority = maxval(prt_params%organ_param_id(:))
if(n_max_priority>10 .or. n_max_priority<0)then
write(fates_log(),*) 'was unable to interpret prt_params%organ_param_id'
write(fates_log(),*) 'for cnp allocation, there should be non-zero values <10'