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

Define new fates_param_reader_type type to abstract HLM-side param I/O #1096

Merged
merged 6 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
59 changes: 54 additions & 5 deletions main/FatesInterfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,16 @@ 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
! TODO(jpalex): remove this direct reference to HLM code.
use CLMFatesParamInterfaceMod , only : HLM_FatesReadParameters => FatesReadParameters
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 @@ -173,6 +180,8 @@ module FatesInterfaceMod
public :: set_bcs
public :: UpdateFatesRMeansTStep
public :: InitTimeAveragingGlobals

private :: FatesReadParameters

contains

Expand Down Expand Up @@ -726,7 +735,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 +750,21 @@ 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
! TODO(jpalex): make non-optional once all HLMs pass it in.
class(fates_param_reader_type), optional, 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()
if (present(param_reader)) then
! new, Fates-side.
call FatesReadParameters(param_reader)
else
! old, HLM-side.
call HLM_FatesReadParameters()
end if

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

Expand Down Expand Up @@ -2142,5 +2159,37 @@ subroutine SeedlingParPatch(cpatch, &
return
end subroutine SeedlingParPatch

!-----------------------------------------------------------------------
! 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