Skip to content

Commit

Permalink
Forced FATES initializations during clm_inst to all go through clm_fa…
Browse files Browse the repository at this point in the history
…tes%init(). Allocation of the fates() vector and some updated naming of subroutines accompany.
  • Loading branch information
rgknox committed May 19, 2016
1 parent dc7a6fb commit 5c606db
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 65 deletions.
6 changes: 3 additions & 3 deletions components/clm/src/ED/main/FatesInterfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module FatesInterfaceMod
contains

! Procedures for initializing FATES threaded memory and communicators
procedure, public :: fates_init
procedure, public :: init
procedure, public :: fates_clean
procedure, public :: site_init
procedure, public :: fates_restart
Expand All @@ -52,7 +52,7 @@ module FatesInterfaceMod

contains

subroutine fates_init(this,bounds_clump)
subroutine init(this,bounds_clump)

implicit none

Expand All @@ -70,7 +70,7 @@ subroutine fates_init(this,bounds_clump)
allocate (this%sites(bounds_clump%begg:bounds_clump%endg))

return
end subroutine fates_init
end subroutine init

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

Expand Down
10 changes: 5 additions & 5 deletions components/clm/src/main/clm_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate)
if (use_ed) then
! if ED enabled, summarize productivity fluxes onto CLM history file structure
call t_startf('edclmsumprodfluxes')
call clm_fates%fates2hlm_inst%SummarizeProductivityFluxes( bounds_clump, &
call clm_fates%fates2hlm%SummarizeProductivityFluxes( bounds_clump, &
clm_fates%fates(nc)%sites(bounds_clump%begg:bounds_clump%endg))
call t_stopf('edclmsumprodfluxes')
endif
Expand Down Expand Up @@ -710,7 +710,7 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate)
c13_cnveg_carbonflux_inst, c13_cnveg_carbonstate_inst, &
c14_cnveg_carbonflux_inst, c14_cnveg_carbonstate_inst, &
cnveg_nitrogenflux_inst, cnveg_nitrogenstate_inst, &
clm_fates%fates2hlm_inst, &
clm_fates%fates2hlm, &
soilbiogeochem_carbonflux_inst, soilbiogeochem_carbonstate_inst, &
c13_soilbiogeochem_carbonflux_inst, c13_soilbiogeochem_carbonstate_inst, &
c14_soilbiogeochem_carbonflux_inst, c14_soilbiogeochem_carbonstate_inst, &
Expand Down Expand Up @@ -738,7 +738,7 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate)

! Zero some of the FATES->CLM communicators
if (use_ed) then
call clm_fates%fates2hlm_inst%SetValues(bounds_clump,0._r8)
call clm_fates%fates2hlm%SetValues(bounds_clump,0._r8)
end if

! Dry Deposition of chemical tracers (Wesely (1998) parameterizaion)
Expand Down Expand Up @@ -854,7 +854,7 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate)
filter(nc)%num_pcropp, filter(nc)%pcropp, doalb, &
cnveg_state_inst, &
cnveg_carbonflux_inst, cnveg_carbonstate_inst, &
clm_fates%fates2hlm_inst, &
clm_fates%fates2hlm, &
soilbiogeochem_carbonflux_inst, soilbiogeochem_carbonstate_inst, &
soilbiogeochem_state_inst, &
soilbiogeochem_nitrogenflux_inst, soilbiogeochem_nitrogenstate_inst, &
Expand All @@ -871,7 +871,7 @@ subroutine clm_drv(doalb, nextsw_cday, declinp1, declin, rstwr, nlend, rdate)
c13_soilbiogeochem_carbonflux_inst, c13_soilbiogeochem_carbonstate_inst, &
c14_soilbiogeochem_carbonflux_inst, c14_soilbiogeochem_carbonstate_inst, &
soilbiogeochem_nitrogenflux_inst, soilbiogeochem_nitrogenstate_inst, &
clm_fates%fates2hlm_inst, &
clm_fates%fates2hlm, &
clm_fates%fates(nc)%sites(bounds_clump%begg:bounds_clump%endg))
end if

Expand Down
30 changes: 4 additions & 26 deletions components/clm/src/main/clm_instMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module clm_instMod
use UrbanParamsType , only : IsSimpleBuildTemp, IsProgBuildTemp
use SoilBiogeochemDecompCascadeConType , only : decomp_cascade_con
use CNDVType , only : dgv_ecophyscon ! Constants
use EDEcophysConType , only : EDecophyscon ! ED Constants

!-----------------------------------------
! Definition of component types
Expand Down Expand Up @@ -168,12 +167,11 @@ subroutine clm_instInit(bounds)
use SoilBiogeochemDecompCascadeBGCMod , only : init_decompcascade_bgc
use SoilBiogeochemDecompCascadeCNMod , only : init_decompcascade_cn
use SoilBiogeochemDecompCascadeContype , only : init_decomp_cascade_constants
use EDEcophysConType , only : EDecophysconInit
use EDPftVarcon , only : EDpftvarcon_inst

use initVerticalMod , only : initVertical
use accumulMod , only : print_accum_fields
use SoilWaterRetentionCurveFactoryMod , only : create_soil_water_retention_curve
use decompMod , only : get_proc_bounds, get_proc_clumps, get_clump_bounds
use decompMod , only : get_proc_bounds
!
! !ARGUMENTS
type(bounds_type), intent(in) :: bounds ! processor bounds
Expand Down Expand Up @@ -429,27 +427,7 @@ subroutine clm_instInit(bounds)
! NOTE (RGK, 04-25-2016) : Updating names, ED is now part of FATES
! Incrementally changing to ED names to FATES

! INTERF-TODO: we should not be allocating thread and sites when ed
! is not on, but until canopyfluxes and surfaceabledo are teased apart, the
! allocation needs to happen so that it can be passed as an argument (RGK)

nclumps = get_proc_clumps()
allocate(clm_fates%fates(nclumps))
do nc = 1,nclumps
call get_clump_bounds(nc, bounds_clump)
! INTERF-TODO: THIS CALL SHOULD NOT CALL FATES(NC) DIRECTLY
! BUT IT SHOULD PASS bounds_clump TO A CLM_FATES WRAPPER
! WHICH WILL IN TURN PASS A FATES API DEFINED BOUNDS TO FATES_INIT
call clm_fates%fates(nc)%fates_init(bounds_clump)
end do

if( use_ed )then
call clm_fates%Init(bounds)

! INTERF-TODO: AT SOME POINT WE MAY HAVE FATES DOING ITS OWN PARAMETER
! READS, AND THIS CALL WILL BE EMBEDDED IN THE FATES SIDE OF INTERFACE
call EDecophysconInit( EDpftvarcon_inst, numpft )
end if
call clm_fates%Init(bounds,use_ed)


deallocate (h2osno_col)
Expand Down Expand Up @@ -618,7 +596,7 @@ subroutine clm_instRest(bounds, ncid, flag)
end if
end do

call clm_fates%fates2hlm_inst%restart(bounds, ncid, flag)
call clm_fates%fates2hlm%restart(bounds, ncid, flag)

end if

Expand Down
89 changes: 58 additions & 31 deletions components/clm/src/utils/clmfates_interfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module CLMFatesInterfaceMod
use TemperatureType , only : temperature_type
use SoilStateType , only : soilstate_type
use clm_varctl , only : iulog
use clm_varpar , only : numpft
use atm2lndType , only : atm2lnd_type
use SurfaceAlbedoType , only : surfalb_type
use SolarAbsorbedType , only : solarabs_type
Expand All @@ -48,6 +49,7 @@ module CLMFatesInterfaceMod
use clm_time_manager , only : get_days_per_year, get_curr_date
use clm_time_manager , only : get_ref_date, timemgr_datediff
use spmdMod , only : masterproc
use decompMod , only : get_proc_bounds, get_proc_clumps, get_clump_bounds

! Used FATES Modules
use FatesInterfaceMod , only : fates_interface_type
Expand All @@ -56,7 +58,8 @@ module CLMFatesInterfaceMod
use EDTypesMod , only : udata
use EDMainMod , only : ed_ecosystem_dynamics
use EDMainMod , only : ed_update_site

use EDPftVarcon , only : EDpftvarcon_inst
use EDEcophysConType , only : EDecophysconInit
implicit none

type, public :: hlm_fates_interface_type
Expand All @@ -71,11 +74,11 @@ module CLMFatesInterfaceMod

type(fates_interface_type), allocatable :: fates (:)

! fates2hlm_inst (previously called "clm_ed_inst") contains types and variables
! fates2hlm (previously called "clm_ed_inst") contains types and variables
! that are passed back to the driving land model, ie fates-to-hlm.
! usefull to a calling model. In this case HLM means "Hosting Land Model"
! prev: type(ed_clm_type)::ed_clm_inst
type(ed_clm_type) :: fates2hlm_inst
type(ed_clm_type) :: fates2hlm


! These are phenology relevant variables (strange how phenology gets
Expand Down Expand Up @@ -105,7 +108,7 @@ module CLMFatesInterfaceMod

contains

subroutine init(this,bounds_proc)
subroutine init(this,bounds_proc, use_ed)

! ---------------------------------------------------------------------------------
! This initializes the dlm_fates_interface_type
Expand All @@ -128,24 +131,48 @@ subroutine init(this,bounds_proc)
! Input Arguments
class(hlm_fates_interface_type), intent(inout) :: this
type(bounds_type),intent(in) :: bounds_proc


! Initialize the FATES communicators with the HLM
! This involves to stages
! 1) allocate the vectors hlm_inst
! 2) add the history variables defined in clm_inst to the history machinery
call this%fates2hlm_inst%Init(bounds_proc)

! Initialize ED phenology variables
! This also involves two stages
! 1) allocate the vectors in phen_inst
! 2) add the phenology history variables to the history machinery
call this%phen_inst%Init(bounds_proc)

! ---------------------------------------------------------------------------------
! Initialization of the state-threads is handled by the calling subroutine
! clm_instInit
! ---------------------------------------------------------------------------------
logical,intent(in) :: use_ed ! NEEDS TO BE PASSED (FOR NOW)
! BC THE FATES SITE VECTORS
! NEED TO BE GENERATED
! FOR NON-ED AS WELL. SO
! ONLY PART OF THIS MAY BE OPERATIVE
! local variables
integer :: nclumps ! Number of threads
integer :: nc ! thread index
type(bounds_type) :: bounds_clump

if (use_ed) then

! Initialize the FATES communicators with the HLM
! This involves to stages
! 1) allocate the vectors
! 2) add the history variables defined in clm_inst to the history machinery
call this%fates2hlm%Init(bounds_proc)

! Initialize ED phenology variables
! This also involves two stages
! 1) allocate the vectors in phen_inst
! 2) add the phenology history variables to the history machinery
call this%phen_inst%Init(bounds_proc)


call EDecophysconInit( EDpftvarcon_inst, numpft )

end if


nclumps = get_proc_clumps()
allocate(this%fates(nclumps))

do nc = 1,nclumps
call get_clump_bounds(nc, bounds_clump)
! INTERF-TODO: BOUNDS CLUMP SHOULD NOT BE PASSED TO THE FATES PUBLIC
! WILL REQUIRE MAPPING PRIOR TO THIS STEP AND EITHER A FATES-BOUNDS
! OR NATIVE TYPE SHOULD BE PASSED, ALL THAT HAPPENS IN THIS CALL IS ALLOCATION
! OF SITES()
call this%fates(nc)%init(bounds_clump)
end do


end subroutine init

Expand All @@ -163,7 +190,7 @@ subroutine fates2hlm_link(this, bounds_clump, nc, waterstate_inst, canopystate_i
type(canopystate_type) , intent(inout) :: canopystate_inst
integer, intent(in) :: nc

call this%fates2hlm_inst%ed_clm_link( bounds_clump, &
call this%fates2hlm%ed_clm_link( bounds_clump, &
this%fates(nc)%sites(bounds_clump%begg:bounds_clump%endg), &
this%phen_inst, &
waterstate_inst, &
Expand Down Expand Up @@ -219,7 +246,7 @@ subroutine dynamics_driv(this, nc, bounds_clump, &
! ---------------------------------------------------------------------------------


call this%fates2hlm_inst%SetValues( bounds_clump, 0._r8 )
call this%fates2hlm%SetValues( bounds_clump, 0._r8 )

! timing statements.
udata%n_sub = get_days_per_year()
Expand All @@ -246,17 +273,17 @@ subroutine dynamics_driv(this, nc, bounds_clump, &
! where most things happen
do g = bounds_clump%begg,bounds_clump%endg
if (this%fates(nc)%sites(g)%istheresoil) then
call ed_ecosystem_dynamics(this%fates(nc)%sites(g), &
this%fates2hlm_inst, &
this%phen_inst, atm2lnd_inst, &
call ed_ecosystem_dynamics(this%fates(nc)%sites(g), &
this%fates2hlm, &
this%phen_inst, atm2lnd_inst, &
soilstate_inst, temperature_inst, waterstate_inst)

call ed_update_site(this%fates(nc)%sites(g))
endif
enddo

! link to CLM/ALM structures
call this%fates2hlm_inst%ed_clm_link( bounds_clump, &
call this%fates2hlm%ed_clm_link( bounds_clump, &
this%fates(nc)%sites(bounds_clump%begg:bounds_clump%endg), &
this%phen_inst, &
waterstate_inst, &
Expand All @@ -274,7 +301,7 @@ end subroutine dynamics_driv

! ------------------------------------------------------------------------------------
! THESE WRAPPERS MAY COME IN HANDY, KEEPING FOR NOW
! subroutine set_fates2hlm_inst(this,bounds_clump, setval_scalar)
! subroutine set_fates2hlm(this,bounds_clump, setval_scalar)
!
! ! This is a simple wrapper to flush some FATES -> CLM communicators
!
Expand All @@ -283,8 +310,8 @@ end subroutine dynamics_driv
! type(bounds_type),intent(in) :: bounds_clump
! real(r8),intent(in) :: setval_scalar ! This value will flush all
!
! call this%fates2hlm_inst%SetValues( bounds_clump, setval_scalar )
! end subroutine set_fates2hlm_inst
! call this%fates2hlm%SetValues( bounds_clump, setval_scalar )
! end subroutine set_fates2hlm
! ------------------------------------------------------------------------------------
! subroutine phen_accvars_init(this,bounds_clump)
!
Expand Down

0 comments on commit 5c606db

Please sign in to comment.