Skip to content

Commit

Permalink
Merge remote-tracking branch 'glemfork/lnd/fates-api-readparams-refac…
Browse files Browse the repository at this point in the history
…tor' (PR #6027)

This PR refactors the elm-fates interface to avoid having fates call elmfates_interfacemod.
FatesReadParameters has been moved from the aforementioned module into FATES and
takes in an HLM-provided fates_param_reader_type to read the parameters from disk.
The existing SetFatesGlobalElements1 method now takes in an optional fates_param_reader_type.

Upcoming PR's will modify the HLM's to construct and pass in instances of fates_param_reader_type
(which will basically call the HLM-side ParametersFromNetCDF method), and then remove the old code path.

This work is ported from ESCOMP/CTSM#2198 and is associated with NGEET/fates#1096

Fixes #6029

[BFB]
  • Loading branch information
peterdschwartz committed Feb 7, 2024
2 parents 075645f + 43d7472 commit 67abd00
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 66 deletions.
2 changes: 1 addition & 1 deletion components/elm/src/external_models/fates
2 changes: 1 addition & 1 deletion components/elm/src/main/elm_initializeMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module elm_initializeMod
use readParamsMod , only : readSharedParameters, readPrivateParameters
use ncdio_pio , only : file_desc_t
use ELMFatesInterfaceMod , only : ELMFatesGlobals1,ELMFatesGlobals2
use CLMFatesParamInterfaceMod, only: FatesReadPFTs
use ELMFatesParamInterfaceMod, only: FatesReadPFTs
use BeTRSimulationELM, only : create_betr_simulation_elm
!
!-----------------------------------------
Expand Down
18 changes: 10 additions & 8 deletions components/elm/src/main/elmfates_interfaceMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ module ELMFatesInterfaceMod
!
! This is also the only location where CLM code is allowed to see FATES memory
! structures.
! The routines here, that call FATES library routines, will not pass any types defined
! by the driving land model (HLM).
!
! either native type arrays (int,real,log, etc) or packed into ED boundary condition
! structures.
! The routines here, that call FATES library routines, cannot pass most types defined
! by the driving land model (HLM), only native type arrays (int,real,log, etc), implementations
! of fates abstract classes, and references into fates boundary condition structures.
!
! Note that CLM/ALM does use Shared Memory Parallelism (SMP), where processes such as
! the update of state variables are forked. However, IO is not assumed to be
Expand Down Expand Up @@ -176,7 +174,10 @@ module ELMFatesInterfaceMod
use dynSubgridControlMod, only : get_do_harvest ! this gets the namelist value

use FatesInterfaceTypesMod , only : bc_in_type, bc_out_type
use CLMFatesParamInterfaceMod , only : FatesReadParameters

use ELMFatesParamInterfaceMod, only : fates_param_reader_ctsm_impl
use FatesParametersInterface, only : fates_param_reader_type
use FatesParametersInterface, only : fates_parameters_type

use perf_mod , only : t_startf, t_stopf

Expand Down Expand Up @@ -292,6 +293,7 @@ subroutine ELMFatesGlobals1()
integer :: pass_sp
integer :: pass_masterproc
logical :: verbose_output
type(fates_param_reader_ctsm_impl) :: var_reader

if (use_fates) then

Expand Down Expand Up @@ -346,7 +348,7 @@ subroutine ELMFatesGlobals1()
! want fates to handle crops, so again, it should be ignored.
! (RGK 07-2022)

call SetFatesGlobalElements1(use_fates,natpft_size,0)
call SetFatesGlobalElements1(use_fates,natpft_size,0,var_reader)

natpft_size = fates_maxPatchesPerSite

Expand Down Expand Up @@ -3452,6 +3454,6 @@ subroutine GetAndSetTime()

end subroutine GetAndSetTime


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

end module ELMFatesInterfaceMod
93 changes: 37 additions & 56 deletions components/elm/src/main/elmfates_paraminterfaceMod.F90
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
module CLMFatesParamInterfaceMod
module ELMFatesParamInterfaceMod
! NOTE(bja, 2017-01) this code can not go into the main clm-fates
! interface module because of circular dependancies with pftvarcon.

use FatesGlobals, only : fates_log
use FatesParametersInterface, only : fates_parameters_type
use FatesParametersInterface, only : fates_param_reader_type
use shr_kind_mod, only : r8 => shr_kind_r8

implicit none
private

! NOTE(bja, 2017-01) these methods can NOT be part of the clmi-fates
! nterface type because they are called before the instance is
! Extend the fates parameter reader type with Read parameter function
type, extends(fates_param_reader_type) :: fates_param_reader_ctsm_impl
! !PRIVATE MEMBER DATA:
contains
! !PUBLIC MEMBER FUNCTIONS:
procedure, public :: Read ! Read params from disk
end type

public :: fates_param_reader_ctsm_impl

! NOTE(bja, 2017-01) these methods can NOT be part of the hlm-fates
! interface type because they are called before the instance is
! initialized.
public :: FatesReadParameters
public :: FatesReadPFTs
private :: ParametersFromNetCDF
private :: SetParameterDimensions
private :: GetUsedDimensionSizes

logical :: DEBUG = .false.

Expand All @@ -23,61 +32,13 @@ module CLMFatesParamInterfaceMod

contains

!-----------------------------------------------------------------------
subroutine FatesReadParameters()

use elm_varctl, only : use_fates, paramfile, fates_paramfile
use spmdMod, only : masterproc

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

implicit none

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

if (use_fates) then
if (masterproc) then
write(fates_log(), *) 'clmfates_parameterinterfaceMod.F90::'//trim(subname)//' :: CLM reading ED/FATES '//' parameters '
end if

allocate(fates_params)
call fates_params%Init()
call FatesRegisterParams(fates_params)
call SpitFireRegisterParams(fates_params)
call PRTRegisterParams(fates_params)
call FatesSynchronizedParamsInst%RegisterParams(fates_params)

is_host_file = .false.
call ParametersFromNetCDF(fates_paramfile, is_host_file, fates_params)

is_host_file = .true.
call ParametersFromNetCDF(paramfile, is_host_file, 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 if

end subroutine FatesReadParameters

!-----------------------------------------------------------------------
subroutine FatesReadPFTs()

use elm_varctl, only : use_fates, paramfile, fates_paramfile
use spmdMod, only : masterproc

use FatesParametersInterface, only : fates_parameters_type
use EDPftvarcon , only : EDPftvarcon_inst

use fileutils , only : getfil
Expand Down Expand Up @@ -239,6 +200,26 @@ subroutine ParametersFromNetCDF(filename, is_host_file, fates_params)
deallocate(data)
call ncd_pio_closefile(ncid)
end subroutine ParametersFromNetCDF

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

subroutine Read(this, fates_params )
!
! !DESCRIPTION:
! Read 'fates_params' parameters from storage.
!
! USES
use elm_varctl, only : fname_len, paramfile, fates_paramfile
! !ARGUMENTS:
class(fates_param_reader_ctsm_impl) :: this
class(fates_parameters_type), intent(inout) :: fates_params
!-----------------------------------------------------------------------
logical :: is_host_file = .false.

call ParametersFromNetCDF(fates_paramfile, is_host_file, fates_params)

end subroutine Read

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

end module CLMFatesParamInterfaceMod
end module ELMFatesParamInterfaceMod

0 comments on commit 67abd00

Please sign in to comment.