Skip to content

Commit

Permalink
Merge pull request #1096 from johnpaulalex/newint
Browse files Browse the repository at this point in the history
Define new fates_param_reader_type type to abstract HLM-side param I/O
  • Loading branch information
glemieux authored Nov 17, 2023
2 parents 44ba97a + 0344660 commit 0b105be
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 7 deletions.
58 changes: 51 additions & 7 deletions main/FatesInterfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ module FatesInterfaceMod
use EDParamsMod , only : ED_val_history_ageclass_bin_edges
use EDParamsMod , only : ED_val_history_height_bin_edges
use EDParamsMod , only : ED_val_history_coageclass_bin_edges
use CLMFatesParamInterfaceMod , only : FatesReadParameters
use EDParamsMod , only : p_uptake_mode
use EDParamsMod , only : n_uptake_mode
use FatesParametersInterface , only : fates_param_reader_type
use FatesParametersInterface , only : fates_parameters_type
use EDParamsMod , only : FatesRegisterParams, FatesReceiveParams
use SFParamsMod , only : SpitFireRegisterParams, SpitFireReceiveParams
use PRTInitParamsFATESMod , only : PRTRegisterParams, PRTReceiveParams
use FatesSynchronizedParamsMod, only : FatesSynchronizedParamsInst
use EDParamsMod , only : p_uptake_mode
use EDParamsMod , only : n_uptake_mode
use EDTypesMod , only : ed_site_type
use FatesConstantsMod , only : prescribed_p_uptake
use FatesConstantsMod , only : prescribed_n_uptake
Expand Down Expand Up @@ -171,6 +176,8 @@ module FatesInterfaceMod
public :: set_bcs
public :: UpdateFatesRMeansTStep
public :: InitTimeAveragingGlobals

private :: FatesReadParameters
public :: DetermineGridCellNeighbors

logical :: debug = .false. ! for debugging this module
Expand Down Expand Up @@ -727,7 +734,7 @@ end subroutine set_bcs

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

subroutine SetFatesGlobalElements1(use_fates,surf_numpft,surf_numcft)
subroutine SetFatesGlobalElements1(use_fates,surf_numpft,surf_numcft,param_reader)

! --------------------------------------------------------------------------------
!
Expand All @@ -741,13 +748,14 @@ subroutine SetFatesGlobalElements1(use_fates,surf_numpft,surf_numcft)
logical, intent(in) :: use_fates ! Is fates turned on?
integer, intent(in) :: surf_numpft ! Number of PFTs in surface dataset
integer, intent(in) :: surf_numcft ! Number of CFTs in surface dataset
class(fates_param_reader_type), intent(in) :: param_reader ! HLM-provided param file reader

integer :: fates_numpft ! Number of PFTs tracked in FATES

if (use_fates) then

! Self explanatory, read the fates parameter file
call FatesReadParameters()
call FatesReadParameters(param_reader)

fates_numpft = size(prt_params%wood_density,dim=1)

Expand Down Expand Up @@ -2380,5 +2388,41 @@ subroutine DetermineGridCellNeighbors(neighbors,seeds,numg)
call t_stopf('fates-seed-init-decomp')

end subroutine DetermineGridCellNeighbors

end module FatesInterfaceMod

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

!-----------------------------------------------------------------------
! TODO(jpalex): this belongs in FatesParametersInterface.F90, but would require
! untangling the dependencies of the *RegisterParams methods below.
subroutine FatesReadParameters(param_reader)
implicit none

class(fates_param_reader_type), intent(in) :: param_reader ! HLM-provided param file reader

character(len=32) :: subname = 'FatesReadParameters'
class(fates_parameters_type), allocatable :: fates_params

if ( hlm_masterproc == itrue ) then
write(fates_log(), *) 'FatesParametersInterface.F90::'//trim(subname)//' :: CLM reading ED/FATES '//' parameters '
end if

allocate(fates_params)
call fates_params%Init() ! fates_params class, in FatesParameterInterfaceMod
call FatesRegisterParams(fates_params) !EDParamsMod, only operates on fates_params class
call SpitFireRegisterParams(fates_params) !SpitFire Mod, only operates of fates_params class
call PRTRegisterParams(fates_params) ! PRT mod, only operates on fates_params class
call FatesSynchronizedParamsInst%RegisterParams(fates_params) !Synchronized params class in Synchronized params mod, only operates on fates_params class

call param_reader%Read(fates_params)

call FatesReceiveParams(fates_params)
call SpitFireReceiveParams(fates_params)
call PRTReceiveParams(fates_params)
call FatesSynchronizedParamsInst%ReceiveParams(fates_params)

call fates_params%Destroy()
deallocate(fates_params)

end subroutine FatesReadParameters

end module FatesInterfaceMod
29 changes: 29 additions & 0 deletions main/FatesParametersInterface.F90
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,35 @@ module FatesParametersInterface

end type fates_parameters_type

! Abstract class (to be implemented by host land models) to read in
! parameter values.
type, abstract, public :: fates_param_reader_type
contains
! Public functions
procedure(Read_interface), public, deferred :: Read

end type fates_param_reader_type

abstract interface
subroutine Read_interface(this, fates_params )
!
! !DESCRIPTION:
! Read 'fates_params' parameters from (HLM-provided) storage. Note this ignores
! the legacy parameter_type.sync_with_host setting.
!
! USES
import :: fates_param_reader_type
import :: fates_parameters_type
! !ARGUMENTS:
class(fates_param_reader_type) :: this
class(fates_parameters_type), intent(inout) :: fates_params
!-----------------------------------------------------------------------

end subroutine Read_interface

!-----------------------------------------------------------------------
end interface

contains

!-----------------------------------------------------------------------
Expand Down

0 comments on commit 0b105be

Please sign in to comment.