Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

two-stream - b4b Norman and no history changes #1141

Merged
merged 114 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
1a7fdb1
Added two-stream code and common globals
rgknox May 15, 2023
282d8ca
Refactor some fates radiation code. New shared memory, and renamed dr…
rgknox May 15, 2023
013e07f
two-stream changes, updated photosynthesis calls to protect against n…
rgknox May 16, 2023
a11d4ae
cleaning up two-stream calls and comments
rgknox May 16, 2023
b786308
Added fsun to history diagnostics,testing different fsun formulations…
rgknox May 19, 2023
882e02a
added type definition
rgknox May 19, 2023
53ee4a2
All sorts of two-stream and general radiation clean up
rgknox Jun 1, 2023
e7b58da
Updated error logging in twostream to use logging file units and erro…
rgknox Jun 5, 2023
6ccedd5
removed cold init argument for radiation driver start
rgknox Jun 12, 2023
783639b
bug fix related to two-stream radiation updates
rgknox Jun 19, 2023
8e34f39
Various updates and fixes to two-stream, including error checking and…
rgknox Jun 23, 2023
5211412
Fix to the restart order issue
rgknox Jun 23, 2023
5b2129a
moved nlevsclass calculation earlier in subroutine
rgknox Jun 23, 2023
28eab39
Added site level scratch array for the 2stream solver
rgknox Jul 12, 2023
22b6b36
Updated unit tests to handle scratch arrays in twostream
rgknox Jul 14, 2023
ae56d63
Merge up two-stream part 1
rgknox Aug 24, 2023
3e959a8
merge resolution between two-stream and patch/cohort refactor
rgknox Aug 24, 2023
6782b4a
removing layer height profile, for now
rgknox Aug 24, 2023
fe3c57f
Merge branch 'main' into two-stream-clean-api26-v2
rgknox Sep 11, 2023
7dc7c47
conflict resolutions for two-stream
rgknox Sep 12, 2023
6d59ea5
add readme to init bld directory
rgknox Sep 19, 2023
3a6b2dc
Updates to two-stream functional unit tests
rgknox Sep 19, 2023
fd0d926
Connected the radiation model switch in the parameter file to the in-…
rgknox Sep 20, 2023
e2aac37
Merge branch 'two-stream-clean-api26-v2' into two-stream-clean-api26
rgknox Sep 20, 2023
d7396b1
Updated radiation model checks to allow for norman and two-stream. Up…
rgknox Sep 21, 2023
bc03f65
Started a new radiation unit test that is used to target specific can…
rgknox Sep 27, 2023
174f292
Updates to two-stream error reporting, checking the linear solution, …
rgknox Sep 29, 2023
b282476
Merge branch 'two-stream-clean' of github.com:rgknox/fates into two-s…
rgknox Oct 4, 2023
e10595c
Applied higher threshold to two-stream closure check, added forced cl…
rgknox Oct 4, 2023
5217289
Set albedo correction to true in fates two-stream
rgknox Oct 4, 2023
f44848b
Merge branch 'two-stream-clean-albedo' into two-stream-clean
rgknox Oct 4, 2023
713bbad
small updates to two-stream unit tests
rgknox Oct 6, 2023
3c6dee2
Added error tracking in two-stream
rgknox Oct 9, 2023
3966cc8
Updates to error tracking of two-stream
rgknox Oct 16, 2023
1f6eb83
Update biogeochem/FatesAllometryMod.F90
rgknox Oct 17, 2023
25923bc
Update radiation/TwoStreamMLPEMod.F90
rgknox Oct 17, 2023
169a8bd
Updates to functional unit test code
rgknox Oct 17, 2023
b74b021
Merge branch 'two-stream-clean-errcheck' into two-stream-clean
rgknox Oct 17, 2023
4d8bebc
Updates to the history file for twostream
rgknox Oct 18, 2023
b3370b9
Cleaning two-stream and radiation drivers to get correct history diag…
rgknox Oct 18, 2023
460645d
more cleaning of radiation history
rgknox Oct 18, 2023
bd33520
updates to the radiation history diagnostics
rgknox Oct 18, 2023
1a3ae69
Changed the avmu radiation parameter to a constant remembered in the …
rgknox Oct 18, 2023
156a17a
Added isnan() functions instead of comparing to self
rgknox Oct 19, 2023
a26146d
Removed old optional two-stream derivations and now using only B1 and…
rgknox Oct 24, 2023
a9260d0
Added checks on scattering coefficient
rgknox Oct 25, 2023
772d57e
Merge branch 'two-stream-clean' into two-stream-clean-v3solution
rgknox Oct 25, 2023
df2dee1
fixed typo
rgknox Oct 25, 2023
8ff6444
Merge branch 'two-stream-clean-v3solution' into two-stream-clean
rgknox Oct 25, 2023
391a4f6
merge resolution and reverting of inventory init to not dump output
rgknox Oct 25, 2023
c3da9e6
Updated messaging on the param check failure if the fates_rad_model i…
rgknox Oct 26, 2023
789c36a
Updated fail message on rad parameter bounds
rgknox Oct 26, 2023
7f14138
Addressing reviewer comments
rgknox Oct 26, 2023
1aa2ead
removed unused alias in fateshistoryinterface
rgknox Oct 26, 2023
dbb2cfe
fixes to lingering merge conflict resolutions
rgknox Oct 26, 2023
83f8156
Adding in protections to avoid Kb==a in two-stream
rgknox Nov 6, 2023
904c0e4
Merge branch 'two-stream-clean' of github.com:rgknox/fates into two-s…
rgknox Nov 6, 2023
7112368
clean up comments and old text in two-stream code
rgknox Nov 6, 2023
6ca1ccb
Conflict resolution two-stream and api30
rgknox Nov 7, 2023
2e140be
small tweaks to error tracking in fates two-stream
rgknox Nov 8, 2023
9f6f5c2
cleaning up conservation error diagnostics
rgknox Nov 9, 2023
3fa96a3
Tweaking the correction to beam optical depth, needs provisions for n…
rgknox Nov 12, 2023
cb6b677
Initializing two-stream error with the ignore flag
rgknox Nov 17, 2023
24760aa
Tweaks to area squeezing in two-stream
rgknox Nov 21, 2023
d35b9b1
bug fix in area squeezing during two-stream
rgknox Nov 21, 2023
0d7b490
Merge two-stream with api31
rgknox Nov 21, 2023
31ed39b
cleaned up canopy mask logic
rgknox Nov 22, 2023
38c3f1f
Added in code to preserve leaf to cohort scaling in norman mode, will…
rgknox Nov 28, 2023
33c83cb
trivial merge resolution between two-stream and inventory uppdates
rgknox Nov 28, 2023
46ecf39
altnerate reverted form of leaf layer calculation
rgknox Nov 30, 2023
624293b
testing out b4b corrections
rgknox Dec 1, 2023
5f4a8b6
Reverted incorrect nscalar
rgknox Dec 1, 2023
33cb3ae
Merge branch 'two-stream-clean' into two-stream-clean-b4b
rgknox Dec 2, 2023
b88f636
More b4b attempts at two-stream
rgknox Dec 4, 2023
3c0051e
debugging logic ends
rgknox Dec 7, 2023
c71dadb
more b4b attempts at two-stream
rgknox Dec 8, 2023
e0c564f
Merge branch 'two-stream-clean-b4b' into two-stream-clean-b4b2
rgknox Dec 8, 2023
1d64107
making switches in b4b check consistent
rgknox Dec 8, 2023
d4ac49b
reverting history code in two-stream to match main for b4b
rgknox Dec 8, 2023
da54174
attempts to revert history code in 2str to get b4b
rgknox Dec 8, 2023
1df494a
small b4b changes to two-stream
rgknox Dec 12, 2023
56aa325
Creating seperate module for norman rad
rgknox Dec 12, 2023
8cc57c9
fixed some typos
rgknox Dec 13, 2023
7abc732
cleaning up photosynthesis code w/two-stream
rgknox Dec 13, 2023
40f1a2a
Merge branch 'two-stream-clean-b4b-hist' into two-stream-clean-b4b2
rgknox Dec 13, 2023
a3754a1
Reverted history code to be as similar to base as possible
rgknox Dec 13, 2023
a972ff3
more two-stream b4b work
rgknox Dec 14, 2023
c34773a
reinstated ed_laisun_z and ed_laisha_z for b4b tests
rgknox Dec 14, 2023
0c1e890
reverting canopy mask for b4b
rgknox Dec 14, 2023
89aecd1
reworking towards b4b
rgknox Dec 15, 2023
c6da2fe
b4b stuff
rgknox Dec 15, 2023
f6b879e
b4b stuff for two-stream
rgknox Dec 18, 2023
140e6ff
b4b for two-stream
rgknox Dec 18, 2023
36105c3
more b4b stuff
rgknox Dec 19, 2023
312593f
revert history to match main
rgknox Dec 20, 2023
36be028
merge two-stream with lu1
rgknox Dec 20, 2023
62a37f9
removed solver error (redundant with conservation error)
rgknox Dec 20, 2023
893d8cf
merge updates on two-stream with luh2, as well as consolidation of ra…
rgknox Dec 21, 2023
b743547
two-stream cleaning up
rgknox Dec 22, 2023
0366819
adding text around preserve_b4b
rgknox Dec 27, 2023
5e4c6df
removed redundant declaration
rgknox Dec 27, 2023
f416029
Updating scipy module importing to work for both new and old conventions
rgknox Jan 3, 2024
9fa0153
added try clause to scipy module loading
rgknox Jan 3, 2024
64eb770
deleted unnecessary comment
rgknox Jan 3, 2024
6935a40
removed unncecessary comment
rgknox Jan 3, 2024
5daf737
set intent in on veg_tempk
rgknox Jan 3, 2024
1642919
removed unused global declarations in history
rgknox Jan 3, 2024
200f024
removing hlm_numSWb use in code, it is redundant
rgknox Jan 3, 2024
f6832c3
two-stream responding to reviewer comments
rgknox Jan 4, 2024
d127f51
resolving more reviewer comments
rgknox Jan 4, 2024
0079a85
Fixing zero protections on two-stream zenith calcualtions
rgknox Jan 10, 2024
9c6f822
Merge branch 'main' into two-stream-clean-b4b-nohist
rgknox Jan 10, 2024
af2c3b9
Fixes to nan checks in fates two-stream
rgknox Jan 12, 2024
7b2cdbe
fixed try statement on module importing in python scipy
rgknox Jan 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
291 changes: 169 additions & 122 deletions biogeochem/EDCanopyStructureMod.F90

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions biogeochem/EDPatchDynamicsMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ module EDPatchDynamicsMod
use FatesConstantsMod , only : fates_tiny
use FatesConstantsMod , only : nocomp_bareground
use FatesInterfaceTypesMod , only : hlm_use_planthydro
use FatesInterfaceTypesMod , only : hlm_numSWb
use FatesInterfaceTypesMod , only : bc_in_type
use FatesInterfaceTypesMod , only : numpft
use FatesInterfaceTypesMod , only : hlm_stepsize
Expand Down Expand Up @@ -106,6 +105,7 @@ module EDPatchDynamicsMod
use FatesRunningMeanMod, only : ema_sdlng_mdd
use FatesRunningMeanMod, only : ema_sdlng_emerg_h2o, ema_sdlng_mort_par, ema_sdlng2sap_par
use FatesRunningMeanMod, only : ema_24hr, fixed_24hr, ema_lpa, ema_longterm
use FatesRadiationMemMod, only : num_swb

! CIME globals
use shr_infnan_mod , only : nan => shr_infnan_nan, assignment(=)
Expand Down Expand Up @@ -603,7 +603,7 @@ subroutine spawn_patches( currentSite, bc_in)
allocate(newPatch)

call newPatch%Create(age, site_areadis, i_landusechange_receiverpatchlabel, i_nocomp_pft, &
hlm_numSWb, numpft, currentSite%nlevsoil, hlm_current_tod, &
num_swb, numpft, currentSite%nlevsoil, hlm_current_tod, &
regeneration_model)

! Initialize the litter pools to zero, these
Expand Down Expand Up @@ -2773,8 +2773,9 @@ subroutine fuse_2_patches(csite, dp, rp)
rp%zstar = (dp%zstar*dp%area + rp%zstar*rp%area) * inv_sum_area
rp%c_stomata = (dp%c_stomata*dp%area + rp%c_stomata*rp%area) * inv_sum_area
rp%c_lblayer = (dp%c_lblayer*dp%area + rp%c_lblayer*rp%area) * inv_sum_area
rp%radiation_error = (dp%radiation_error*dp%area + rp%radiation_error*rp%area) * inv_sum_area

rp%rad_error(1) = (dp%rad_error(1)*dp%area + rp%rad_error(1)*rp%area) * inv_sum_area
rp%rad_error(2) = (dp%rad_error(2)*dp%area + rp%rad_error(2)*rp%area) * inv_sum_area

rp%area = rp%area + dp%area !THIS MUST COME AT THE END!

!insert donor cohorts into recipient patch
Expand Down
116 changes: 112 additions & 4 deletions biogeochem/FatesAllometryMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ module FatesAllometryMod
use FatesConstantsMod, only : calloc_abs_error
use FatesConstantsMod, only : fates_unset_r8
use FatesConstantsMod, only : itrue
use FatesConstantsMod, only : nearzero
use shr_log_mod , only : errMsg => shr_log_errMsg
use FatesGlobals , only : fates_log
use FatesGlobals , only : endrun => fates_endrun
use FatesGlobals , only : FatesWarn,N2S,A2S,I2S
use EDParamsMod , only : nlevleaf, dinc_vai
use EDParamsMod , only : nclmax
use EDParamsMod , only : nlevleaf,dinc_vai,dlower_vai
use EDParamsMod , only : nclmax
use DamageMainMod , only : GetCrownReduction

implicit none
Expand Down Expand Up @@ -125,7 +126,8 @@ module FatesAllometryMod
public :: set_root_fraction ! Generic wrapper to calculate normalized
! root profiles
public :: leafc_from_treelai ! Calculate target leaf carbon for a given treelai for SP mode

public :: VegAreaLayer

logical , parameter :: verbose_logging = .false.
character(len=*), parameter :: sourcefile = __FILE__

Expand Down Expand Up @@ -2436,7 +2438,8 @@ real(r8) function decay_coeff_kn(pft,vcmax25top)
end function decay_coeff_kn

! =====================================================================================
subroutine ForceDBH( ipft, crowndamage, canopy_trim, elongf_leaf, elongf_stem, d, h, bdead, bl )

subroutine ForceDBH( ipft, crowndamage, canopy_trim, elongf_leaf, elongf_stem, d, h, bdead, bl )

! =========================================================================
! This subroutine estimates the diameter based on either the structural biomass
Expand Down Expand Up @@ -2586,6 +2589,111 @@ subroutine ForceDBH( ipft, crowndamage, canopy_trim, elongf_leaf, elongf_stem, d
return
end subroutine ForceDBH

! =========================================================================

subroutine VegAreaLayer(tree_lai,tree_sai,tree_height,iv,nv,pft,snow_depth, &
vai_top,vai_bot, elai_layer,esai_layer,tlai_layer,tsai_layer)

! -----------------------------------------------------------------------------------
! This routine returns the exposed leaf and stem areas (m2 of leaf and stem) per m2 of
! ground inside the crown, for the leaf-layer specified.
! -----------------------------------------------------------------------------------

real(r8),intent(in) :: tree_lai ! the in-crown leaf area index for the plant
! [m2 leaf/m2 crown footprint]
real(r8),intent(in) :: tree_sai ! the in-crown stem area index for the plant
! [m2 stem/m2 crown footprint]
real(r8),intent(in) :: tree_height ! the height of the plant [m]
integer,intent(in) :: iv ! vegetation layer index
integer,intent(in) :: nv ! this plants total number of veg layers
integer,intent(in) :: pft ! plant functional type index
real(r8),intent(in) :: snow_depth ! the depth of snow on the ground [m]
real(r8),intent(out) :: vai_top
real(r8),intent(out) :: vai_bot ! the VAI of the bin top and bottom
real(r8),intent(out) :: elai_layer ! exposed leaf area index of the layer
real(r8),intent(out) :: esai_layer ! exposed stem area index of the layer
real(r8),optional,intent(out) :: tlai_layer ! total leaf area index of the layer
real(r8),optional,intent(out) :: tsai_layer ! total stem area index of the layer

! [m2 of leaf in bin / m2 crown footprint]
real(r8) :: tree_vai ! the in-crown veg area index for the plant
real(r8) :: fraction_exposed ! fraction of the veg media that is above snow
real(r8) :: layer_top_height ! Physical height of the layer top relative to ground [m]
real(r8) :: layer_bot_height ! Physical height of the layer bottom relative to ground [m]
real(r8) :: tlai,tsai ! temporary total area indices [m2/m2]
real(r8) :: fleaf ! fraction of biomass in layer that is leaf
real(r8) :: remainder ! old-method: remainder of biomass in last bin
integer, parameter :: layer_height_const_depth = 1 ! constant physical depth assumption
integer, parameter :: layer_height_const_lad = 2 ! constant leaf area depth assumption
integer, parameter :: layer_height_method = layer_height_const_depth
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the background here on the layer_height_method? Will one method be choosen later or be converted to a formal parameter (i.e. moved into the parameter file)? A think a few code comments here explaining the rationale for the hard coded value would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant depth assumption is the default, and is equivalent to the way we currently do things in the canopy summarization code. I added the alternative so that we have the option to explore it in the future. I have not done a thorough investigation of it yet though.


tree_vai = tree_lai + tree_sai

if_any_vai: if(tree_vai>0._r8)then

if(iv==0)then
vai_top = 0.0
vai_bot = tree_vai
else

if(iv>1)then
vai_top = dlower_vai(iv) - dinc_vai(iv)
else
vai_top = 0._r8
end if

if(iv<nv) then
vai_bot = dlower_vai(iv)
else
vai_bot = tree_vai
end if
end if

if(layer_height_method .eq. layer_height_const_depth)then
if(iv==0)then
layer_top_height = tree_height
layer_bot_height = tree_height*(1._r8 - prt_params%crown_depth_frac(pft))
else
layer_top_height = tree_height*(1._r8 - real(iv-1,r8)/real(nv,r8)*prt_params%crown_depth_frac(pft))
layer_bot_height = tree_height*(1._r8 - real(iv,r8)/real(nv,r8)*prt_params%crown_depth_frac(pft))
end if
else
layer_top_height = tree_height*(1._r8 - prt_params%crown_depth_frac(pft)*vai_top/tree_vai)
layer_bot_height = tree_height*(1._r8 - prt_params%crown_depth_frac(pft)*vai_bot/tree_vai)
end if

fraction_exposed = 1._r8 - max(0._r8,(min(1._r8, (snow_depth-layer_bot_height)/(layer_top_height-layer_bot_height))))

tlai = (vai_bot-vai_top) * tree_lai / tree_vai
tsai = (vai_bot-vai_top) * tree_sai / tree_vai

if(present(tlai_layer)) tlai_layer = tlai
if(present(tsai_layer)) tsai_layer = tsai

elai_layer = fraction_exposed * tlai
esai_layer = fraction_exposed * tsai

! Update the vai at the bottom to be removed/decreased if there is no exposure
! set the vai top and bottoms to the snow layer if below
!vai_top = min(vai_top,fraction_exposed*tree_vai)

vai_bot = vai_top + fraction_exposed*(vai_bot-vai_top)

else

if(present(tlai_layer)) tlai_layer = 0._r8
if(present(tsai_layer)) tsai_layer = 0._r8
elai_layer = 0._r8
esai_layer = 0._r8
vai_bot = 0._r8
vai_top = 0._r8

end if if_any_vai


return
end subroutine VegAreaLayer

! =========================================================================

subroutine cspline(x1,x2,y1,y2,dydx1,dydx2,x,y,dydx)
Expand Down
2 changes: 2 additions & 0 deletions biogeochem/FatesCohortMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ module FatesCohortMod

!---------------------------------------------------------------------------

integer :: twostr_col ! The column index in the two-stream solution that this cohort is part of

! RESPIRATION COMPONENTS
real(r8) :: rdark ! dark respiration [kgC/indiv/s]
real(r8) :: resp_g_tstep ! growth respiration [kgC/indiv/timestep]
Expand Down
66 changes: 35 additions & 31 deletions biogeochem/FatesPatchMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ module FatesPatchMod
use FatesLitterMod, only : litter_type
use PRTGenericMod, only : num_elements
use PRTGenericMod, only : element_list
use EDParamsMod, only : maxSWb, nlevleaf, nclmax, maxpft
use EDParamsMod, only : nlevleaf, nclmax, maxpft
use FatesConstantsMod, only : n_dbh_bins, n_dist_types
use FatesConstantsMod, only : n_rad_stream_types
use FatesConstantsMod, only : t_water_freeze_k_1atm
use FatesRunningMeanMod, only : ema_24hr, fixed_24hr, ema_lpa, ema_longterm
use FatesRunningMeanMod, only : ema_sdlng_emerg_h2o, ema_sdlng_mort_par
use FatesRunningMeanMod, only : ema_sdlng2sap_par, ema_sdlng_mdd

use TwoStreamMLPEMod, only : twostream_type
use FatesRadiationMemMod,only : num_swb
use FatesRadiationMemMod,only : num_rad_stream_types
use FatesInterfaceTypesMod,only : hlm_hio_ignore_val
use shr_infnan_mod, only : nan => shr_infnan_nan, assignment(=)
use shr_log_mod, only : errMsg => shr_log_errMsg

Expand Down Expand Up @@ -111,40 +113,36 @@ module FatesPatchMod
real(r8) :: c_stomata ! mean stomatal conductance of all leaves in the patch [umol/m2/s]
real(r8) :: c_lblayer ! mean boundary layer conductance of all leaves in the patch [umol/m2/s]

!TODO - can we delete these?
real(r8) :: layer_height_profile(nclmax,maxpft,nlevleaf)
real(r8) :: psn_z(nclmax,maxpft,nlevleaf)
real(r8) :: nrmlzd_parprof_pft_dir_z(n_rad_stream_types,nclmax,maxpft,nlevleaf)
real(r8) :: nrmlzd_parprof_pft_dif_z(n_rad_stream_types,nclmax,maxpft,nlevleaf)
real(r8) :: nrmlzd_parprof_dir_z(n_rad_stream_types,nclmax,nlevleaf)
real(r8) :: nrmlzd_parprof_dif_z(n_rad_stream_types,nclmax,nlevleaf)
real(r8) :: nrmlzd_parprof_pft_dir_z(num_rad_stream_types,nclmax,maxpft,nlevleaf)
real(r8) :: nrmlzd_parprof_pft_dif_z(num_rad_stream_types,nclmax,maxpft,nlevleaf)

!---------------------------------------------------------------------------

! RADIATION
real(r8) :: radiation_error ! radiation error [W/m2]
real(r8) :: rad_error(num_swb) ! radiation consv error by band [W/m2]
real(r8) :: fcansno ! fraction of canopy covered in snow [0-1]
logical :: solar_zenith_flag ! integer flag specifying daylight (based on zenith angle)
real(r8) :: solar_zenith_angle ! solar zenith angle [radians]
real(r8) :: gnd_alb_dif(maxSWb) ! ground albedo for diffuse rad, both bands [0-1]
real(r8) :: gnd_alb_dir(maxSWb) ! ground albedo for direct rad, both bands [0-1]

real(r8) :: gnd_alb_dif(num_swb) ! ground albedo for diffuse rad, both bands [0-1]
real(r8) :: gnd_alb_dir(num_swb) ! ground albedo for direct rad, both bands [0-1]


! organized by canopy layer, pft, and leaf layer
real(r8) :: fabd_sun_z(nclmax,maxpft,nlevleaf) ! sun fraction of direct light absorbed [0-1]
real(r8) :: fabd_sha_z(nclmax,maxpft,nlevleaf) ! shade fraction of direct light absorbed [0-1]
real(r8) :: fabi_sun_z(nclmax,maxpft,nlevleaf) ! sun fraction of indirect light absorbed [0-1]
real(r8) :: fabi_sha_z(nclmax,maxpft,nlevleaf) ! shade fraction of indirect light absorbed [0-1]
real(r8) :: ed_parsun_z(nclmax,maxpft,nlevleaf) ! PAR absorbed in the sun [W/m2]
real(r8) :: ed_parsha_z(nclmax,maxpft,nlevleaf) ! PAR absorbed in the shade [W/m2]
real(r8) :: f_sun(nclmax,maxpft,nlevleaf) ! fraction of leaves in the sun [0-1]
real(r8) :: ed_laisun_z(nclmax,maxpft,nlevleaf)
real(r8) :: ed_laisha_z(nclmax,maxpft,nlevleaf)
real(r8) :: f_sun(nclmax,maxpft,nlevleaf) ! fraction of leaves in the sun [0-1]


! radiation profiles for comparison against observations
real(r8) :: parprof_pft_dir_z(nclmax,maxpft,nlevleaf) ! direct-beam PAR profile through canopy, by canopy, PFT, leaf level [W/m2]
real(r8) :: parprof_pft_dif_z(nclmax,maxpft,nlevleaf) ! diffuse PAR profile through canopy, by canopy, PFT, leaf level [W/m2]
real(r8) :: parprof_dir_z(nclmax,nlevleaf) ! direct-beam PAR profile through canopy, by canopy, leaf level [W/m2]
real(r8) :: parprof_dif_z(nclmax,nlevleaf) ! diffuse PAR profile through canopy, by canopy, leaf level [W/m2]

real(r8), allocatable :: tr_soil_dir(:) ! fraction of incoming direct radiation transmitted to the soil as direct, by numSWB [0-1]
real(r8), allocatable :: tr_soil_dif(:) ! fraction of incoming diffuse radiation that is transmitted to the soil as diffuse [0-1]
Expand All @@ -155,6 +153,10 @@ module FatesPatchMod
real(r8), allocatable :: sabs_dir(:) ! fraction of incoming direct radiation that is absorbed by the canopy
real(r8), allocatable :: sabs_dif(:) ! fraction of incoming diffuse radiation that is absorbed by the canopy

! Twostream data structures
type(twostream_type) :: twostr ! This holds all two-stream data and procedures


!---------------------------------------------------------------------------

! ROOTS
Expand Down Expand Up @@ -318,16 +320,13 @@ subroutine NanValues(this)
this%ncan(:,:) = fates_unset_int
this%c_stomata = nan
this%c_lblayer = nan
this%layer_height_profile(:,:,:) = nan

this%psn_z(:,:,:) = nan
this%nrmlzd_parprof_pft_dir_z(:,:,:,:) = nan
this%nrmlzd_parprof_pft_dif_z(:,:,:,:) = nan
this%nrmlzd_parprof_dir_z(:,:,:) = nan
this%nrmlzd_parprof_dir_z(:,:,:) = nan

! RADIATION
this%radiation_error = nan
this%rad_error(:) = nan
this%fcansno = nan
this%solar_zenith_flag = .false.
this%solar_zenith_angle = nan
Expand All @@ -336,16 +335,14 @@ subroutine NanValues(this)
this%fabd_sun_z(:,:,:) = nan
this%fabd_sha_z(:,:,:) = nan
this%fabi_sun_z(:,:,:) = nan
this%fabi_sha_z(:,:,:) = nan
this%fabi_sha_z(:,:,:) = nan
this%ed_laisun_z(:,:,:) = nan
this%ed_laisha_z(:,:,:) = nan
this%ed_parsun_z(:,:,:) = nan
this%ed_parsha_z(:,:,:) = nan
this%f_sun(:,:,:) = nan
this%parprof_pft_dir_z(:,:,:) = nan
this%parprof_pft_dif_z(:,:,:) = nan
this%parprof_dir_z(:,:) = nan
this%parprof_dif_z(:,:) = nan
this%tr_soil_dir(:) = nan
this%tr_soil_dif(:) = nan
this%tr_soil_dir_dif(:) = nan
Expand Down Expand Up @@ -418,19 +415,17 @@ subroutine ZeroValues(this)
this%psn_z(:,:,:) = 0.0_r8
this%nrmlzd_parprof_pft_dir_z(:,:,:,:) = 0.0_r8
this%nrmlzd_parprof_pft_dif_z(:,:,:,:) = 0.0_r8
this%nrmlzd_parprof_dir_z(:,:,:) = 0.0_r8
this%nrmlzd_parprof_dif_z(:,:,:) = 0.0_r8

! RADIATION
this%radiation_error = 0.0_r8
this%rad_error(:) = 0.0_r8
this%fabd_sun_z(:,:,:) = 0.0_r8
this%fabd_sha_z(:,:,:) = 0.0_r8
this%fabi_sun_z(:,:,:) = 0.0_r8
this%fabi_sha_z(:,:,:) = 0.0_r8
this%ed_parsun_z(:,:,:) = 0.0_r8
this%ed_parsha_z(:,:,:) = 0.0_r8
this%ed_laisun_z(:,:,:) = 0.0_r8
this%ed_laisha_z(:,:,:) = 0.0_r8
this%ed_parsha_z(:,:,:) = 0.0_r8
this%ed_laisun_z(:,:,:) = 0._r8
this%ed_laisha_z(:,:,:) = 0._r8
this%f_sun = 0.0_r8
this%tr_soil_dir_dif(:) = 0.0_r8
this%fab(:) = 0.0_r8
Expand Down Expand Up @@ -591,7 +586,11 @@ subroutine Create(this, age, area, label, nocomp_pft, num_swb, num_pft, &

! initialize litter
call this%InitLitter(num_pft, num_levsoil)


this%twostr%scelg => null() ! The radiation module will check if this
! is associated, since it is not, it will then
! initialize and allocate

! assign known patch attributes
this%age = age
this%age_class = 1
Expand Down Expand Up @@ -646,7 +645,12 @@ subroutine FreeMemory(this, regeneration_model, numpft)
endif
ccohort => ncohort
end do


! Deallocate Radiation scattering elements
if(associated(this%twostr%scelg)) then
call this%twostr%DeallocTwoStream()
end if

! deallocate all litter objects
do el=1,num_elements
call this%litter(el)%DeallocateLitt()
Expand Down
Loading