Skip to content

Commit

Permalink
Merge pull request #3286 from GEOS-ESM/feature/wdboggs/add_accumulati…
Browse files Browse the repository at this point in the history
…on_aspect

Add Aspect for Frequency/Accumulation
  • Loading branch information
darianboggs authored Jan 10, 2025
2 parents 4bb6d82 + 2bae26e commit 2256498
Show file tree
Hide file tree
Showing 24 changed files with 346 additions and 107 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add accumulation type variable to VariableSpec and ComponentSpecParser
- Add run_dt to ComponentSpec and ComponentSpecParser
- Add run_dt to FieldSpec
- Add FrequencyAspect

### Changed

Expand Down
2 changes: 1 addition & 1 deletion generic3g/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ esma_add_fortran_submodules(
SUBDIRECTORY ComponentSpecParser
SOURCES parse_child.F90 parse_children.F90 parse_connections.F90
parse_var_specs.F90 parse_geometry_spec.F90 parse_component_spec.F90
parse_setservices.F90 parse_run_dt.F90)
parse_setservices.F90 parse_timestep.F90)

esma_add_fortran_submodules(
TARGET MAPL.generic3g
Expand Down
10 changes: 5 additions & 5 deletions generic3g/ComponentSpecParser.F90
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module mapl3g_ComponentSpecParser
public :: parse_child
public :: parse_SetServices
public :: parse_geometry_spec
public :: parse_run_dt
public :: parse_timestep

!!$ public :: parse_ChildSpecMap
!!$ public :: parse_ChildSpec
Expand All @@ -63,7 +63,7 @@ module mapl3g_ComponentSpecParser
character(*), parameter :: KEY_UNGRIDDED_DIM_COORDINATES = 'coordinates'
character(*), parameter :: KEY_VERTICAL_DIM_SPEC = 'vertical_dim_spec'
character(*), parameter :: KEY_ACCUMULATION_TYPE = 'accumulation_type'
character(*), parameter :: KEY_RUN_DT = 'run_dt'
character(*), parameter :: KEY_TIMESTEP = 'timestep'

!>
! Submodule declarations
Expand Down Expand Up @@ -112,11 +112,11 @@ module function parse_child(hconfig, rc) result(child)
integer, optional, intent(out) :: rc
end function parse_child

module function parse_run_dt(hconfig, rc) result(run_dt)
type(ESMF_TimeInterval) :: run_dt
module function parse_timestep(hconfig, rc) result(timestep)
type(ESMF_TimeInterval) :: timestep
type(ESMF_HConfig), intent(in) :: hconfig
integer, optional, intent(out) :: rc
end function parse_run_dt
end function parse_timestep

END INTERFACE

Expand Down
2 changes: 1 addition & 1 deletion generic3g/ComponentSpecParser/parse_component_spec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module function parse_component_spec(hconfig, registry, rc) result(spec)
spec%var_specs = parse_var_specs(mapl_cfg, _RC)
spec%connections = parse_connections(mapl_cfg, _RC)
spec%children = parse_children(mapl_cfg, _RC)
spec%run_dt = parse_run_dt(mapl_cfg, _RC)
spec%timestep = parse_timestep(mapl_cfg, _RC)

call ESMF_HConfigDestroy(mapl_cfg, _RC)

Expand Down
24 changes: 0 additions & 24 deletions generic3g/ComponentSpecParser/parse_run_dt.F90

This file was deleted.

24 changes: 24 additions & 0 deletions generic3g/ComponentSpecParser/parse_timestep.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "MAPL_ErrLog.h"

submodule (mapl3g_ComponentSpecParser) parse_timestep_smod
use MAPL_TimeStringConversion, only: parse_isostring => string_to_esmf_timeinterval
contains

module function parse_timestep(hconfig, rc) result(timestep)
type(ESMF_TimeInterval) :: timestep
type(ESMF_HConfig), intent(in) :: hconfig
integer, optional, intent(out) :: rc

integer :: status
logical :: has_timestep
character(len=:), allocatable :: iso_duration

has_timestep = ESMF_HConfigIsDefined(hconfig, keyString=KEY_TIMESTEP, _RC)
_RETURN_UNLESS(has_timestep)
iso_duration = ESMF_HConfigAsString(hconfig, keyString=KEY_TIMESTEP, _RC)
timestep = parse_isostring(iso_duration, _RC)
_RETURN(_SUCCESS)

end function parse_timestep

end submodule parse_timestep_smod
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ subroutine self_advertise(this, unusable, rc)

integer :: status

call this%registry%set_blanket_geometry(this%geom, this%vertical_grid, this%component_spec%run_dt, _RC)
call this%registry%set_blanket_geometry(this%geom, this%vertical_grid, this%component_spec%timestep, _RC)

_RETURN(_SUCCESS)
_UNUSED_DUMMY(unusable)
Expand Down
26 changes: 17 additions & 9 deletions generic3g/actions/AccumulatorActionInterface.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module mapl3g_AccumulatorActionInterface
use mapl3g_MaxAction
use mapl3g_MinAction
use mapl3g_ExtensionAction
use mapl3g_NullAction
use mapl_ErrorHandling
use mapl_KeywordEnforcer
use esmf, only: ESMF_TypeKind_Flag, ESMF_TYPEKIND_R4, operator(/=)
Expand All @@ -18,15 +19,18 @@ module mapl3g_AccumulatorActionInterface
public :: MEAN_ACCUMULATION
public :: MIN_ACCUMULATION
public :: SIMPLE_ACCUMULATION
public :: NO_ACCUMULATION
public :: INSTANTANEOUS
public :: accumulation_type_is_valid
public :: get_accumulator_action

! This is the default case where accumulation_type is not set.
character(len=*), parameter :: INSTANTANEOUS =''

! These are explicit accumulation_type values.
character(len=*), parameter :: MAX_ACCUMULATION = 'max'
character(len=*), parameter :: MEAN_ACCUMULATION = 'mean'
character(len=*), parameter :: MIN_ACCUMULATION = 'min'
character(len=*), parameter :: SIMPLE_ACCUMULATION = 'simple'
character(len=*), parameter :: NO_ACCUMULATION =''
character(len=8), parameter :: ACCUMULATION_TYPES(4) = [character(len=8) :: &
MAX_ACCUMULATION, MEAN_ACCUMULATION, MIN_ACCUMULATION, SIMPLE_ACCUMULATION]

Expand All @@ -35,8 +39,9 @@ module mapl3g_AccumulatorActionInterface
logical function accumulation_type_is_valid(acctype) result(lval)
character(len=*), optional, intent(in) :: acctype

lval = present(acctype)
if(lval) lval = any(ACCUMULATION_TYPES == acctype)
lval = .FALSE.
if(.not. present(acctype)) return
lval = any(ACCUMULATION_TYPES == acctype)

end function accumulation_type_is_valid

Expand All @@ -48,20 +53,23 @@ subroutine get_accumulator_action(accumulation_type, typekind, action, rc)

integer :: status

allocate(action, source=NullAction())

if(typekind /= ESMF_TYPEKIND_R4) then
_FAIL('Unsupported typekind')
end if
_ASSERT(accumulation_type_is_valid(accumulation_type), 'Unsupported AccumulatorAction')

select case(accumulation_type)
case (SIMPLE_ACCUMULATION)
action = AccumulatorAction(typekind)
allocate(action, source=AccumulatorAction(typekind))
case (MEAN_ACCUMULATION)
action = MeanAction(typekind)
allocate(action, source=MeanAction(typekind))
case (MAX_ACCUMULATION)
action = MaxAction(typekind)
allocate(action, source=MaxAction(typekind))
case (MIN_ACCUMULATION)
action = MinAction(typekind)
allocate(action, source=MinAction(typekind))
case (INSTANTANEOUS)
_FAIL('No AccumulatorAction for instantaneous.')
case default
_FAIL('Unsupported AccumulatorAction')
end select
Expand Down
6 changes: 3 additions & 3 deletions generic3g/registry/StateRegistry.F90
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,11 @@ subroutine allocate(this, rc)
_RETURN(_SUCCESS)
end subroutine allocate

subroutine set_blanket_geometry(this, geom, vertical_grid, run_dt, rc)
subroutine set_blanket_geometry(this, geom, vertical_grid, timestep, rc)
class(StateRegistry), target, intent(inout) :: this
type(ESMF_Geom), optional, intent(in) :: geom
class(VerticalGrid), optional, intent(in) :: vertical_grid
type(ESMF_TimeInterval), optional, intent(in) :: run_dt
type(ESMF_TimeInterval), optional, intent(in) :: timestep
integer, optional, intent(out) :: rc

integer :: status
Expand All @@ -637,7 +637,7 @@ subroutine set_blanket_geometry(this, geom, vertical_grid, run_dt, rc)
extension => iter%of()
spec => extension%get_spec()
if (spec%is_active()) then
call spec%set_geometry(geom, vertical_grid, run_dt, _RC)
call spec%set_geometry(geom, vertical_grid, timestep, _RC)
end if
end do
end associate
Expand Down
28 changes: 24 additions & 4 deletions generic3g/specs/AspectCollection.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module mapl3g_AspectCollection
use mapl3g_GeomAspect
use mapl3g_UnitsAspect
use mapl3g_TypekindAspect

use mapl3g_FrequencyAspect
use mapl3g_UngriddedDimsAspect

use mapl_KeywordEnforcer
Expand All @@ -22,6 +22,7 @@ module mapl3g_AspectCollection
type(UnitsAspect), allocatable :: units_aspect
type(TypekindAspect), allocatable :: typekind_aspect
type(UngriddedDimsAspect), allocatable :: ungridded_dims_aspect
type(FrequencyAspect), allocatable :: frequency_aspect
contains
procedure :: get_aspect ! polymorphic
procedure :: has_aspect ! polymorphic
Expand All @@ -39,6 +40,8 @@ module mapl3g_AspectCollection
procedure :: get_ungridded_dims_aspect
procedure :: set_ungridded_dims_aspect

procedure :: get_frequency_aspect
procedure :: set_frequency_aspect
end type AspectCollection

interface AspectCollection
Expand Down Expand Up @@ -77,6 +80,8 @@ function get_aspect(this, name, rc) result(aspect)
aspect => this%get_typekind_aspect()
case ('UNGRIDDED_DIMS')
aspect => this%get_ungridded_dims_aspect()
case ('FREQUENCY')
aspect => this%get_frequency_aspect()
case default
_FAIL('unknown aspect type: '//name)
end select
Expand All @@ -89,7 +94,7 @@ logical function has_aspect(this, name)
character(*), intent(in) :: name

select case (name)
case ('GEOM', 'UNITS', 'UNGRIDDED_DIMS')
case ('GEOM', 'UNITS', 'UNGRIDDED_DIMS', 'FREQUENCY')
has_aspect = .true.
case default
has_aspect = .false.
Expand All @@ -102,8 +107,6 @@ subroutine set_aspect(this, aspect, rc)
class(StateItemAspect), target, intent(in) :: aspect
integer, optional, intent(out) :: rc

integer :: status

select type (aspect)
type is (GeomAspect)
this%geom_aspect = aspect
Expand All @@ -113,6 +116,8 @@ subroutine set_aspect(this, aspect, rc)
this%typekind_aspect = aspect
type is (UngriddedDimsAspect)
this%ungridded_dims_aspect = aspect
type is (FrequencyAspect)
this%frequency_aspect = aspect
class default
_FAIL('unsupported aspect type: ')
end select
Expand Down Expand Up @@ -181,5 +186,20 @@ subroutine set_ungridded_dims_aspect(this, ungridded_dims_aspect)
this%ungridded_dims_aspect = ungridded_dims_aspect
end subroutine set_ungridded_dims_aspect

function get_frequency_aspect(this) result(frequency_aspect)
type(FrequencyAspect), pointer :: frequency_aspect
class(AspectCollection), target, intent(inout) :: this
frequency_aspect => null()
if(allocated(this%frequency_aspect)) then
frequency_aspect => this%frequency_aspect
end if
end function get_frequency_aspect

subroutine set_frequency_aspect(this, frequency_aspect)
class(AspectCollection), intent(inout) :: this
type(FrequencyAspect), intent(in) :: frequency_aspect
this%frequency_aspect = frequency_aspect
end subroutine set_frequency_aspect

end module mapl3g_AspectCollection

6 changes: 3 additions & 3 deletions generic3g/specs/BracketSpec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,19 @@ subroutine add_to_bundle(this, bundle, rc)
_UNUSED_DUMMY(bundle)
end subroutine add_to_bundle

subroutine set_geometry(this, geom, vertical_grid, run_dt, rc)
subroutine set_geometry(this, geom, vertical_grid, timestep, rc)
class(BracketSpec), intent(inout) :: this
type(ESMF_Geom), optional, intent(in) :: geom
class(VerticalGrid), optional, intent(in) :: vertical_grid
type(ESMF_TimeInterval), optional, intent(in) :: run_dt
type(ESMF_TimeInterval), optional, intent(in) :: timestep
integer, optional, intent(out) :: rc

_FAIL('unimplemented')

_UNUSED_DUMMY(this)
_UNUSED_DUMMY(geom)
_UNUSED_DUMMY(vertical_grid)
_UNUSED_DUMMY(run_dt)
_UNUSED_DUMMY(timestep)
end subroutine set_geometry

subroutine write_formatted(this, unit, iotype, v_list, iostat, iomsg)
Expand Down
1 change: 1 addition & 0 deletions generic3g/specs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ target_sources(MAPL.generic3g PRIVATE
TypekindAspect.F90
UngriddedDimsAspect.F90
UnitsAspect.F90
FrequencyAspect.F90

VariableSpec.F90
StateItem.F90
Expand Down
10 changes: 4 additions & 6 deletions generic3g/specs/ComponentSpec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module mapl3g_ComponentSpec
type(ConnectionVector) :: connections
type(ChildSpecMap) :: children
type(ESMF_HConfig), allocatable :: geom_hconfig ! optional
type(ESMF_TimeInterval), allocatable :: run_dt
type(ESMF_TimeInterval), allocatable :: timestep
contains
procedure :: has_geom_hconfig
procedure :: add_var_spec
Expand All @@ -34,15 +34,15 @@ module mapl3g_ComponentSpec

contains

function new_ComponentSpec(var_specs, connections, run_dt) result(spec)
function new_ComponentSpec(var_specs, connections, timestep) result(spec)
type(ComponentSpec) :: spec
type(VariableSpecVector), optional, intent(in) :: var_specs
type(ConnectionVector), optional, intent(in) :: connections
type(ESMF_TimeInterval), optional, intent(in) :: run_dt
type(ESMF_TimeInterval), optional, intent(in) :: timestep

if (present(var_specs)) spec%var_specs = var_specs
if (present(connections)) spec%connections = connections
if (present(run_dt)) spec%run_dt = run_dt
if (present(timestep)) spec%timestep = timestep

end function new_ComponentSpec

Expand All @@ -57,12 +57,10 @@ subroutine add_var_spec(this, var_spec)
call this%var_specs%push_back(var_spec)
end subroutine add_var_spec


subroutine add_connection(this, conn)
class(ComponentSpec), intent(inout) :: this
class(Connection), intent(in) :: conn
call this%connections%push_back(conn)
end subroutine add_connection

end module mapl3g_ComponentSpec

Loading

0 comments on commit 2256498

Please sign in to comment.