Skip to content

Commit

Permalink
Merge pull request #3408 from GEOS-ESM/feature/tclune/#3406-cleanup
Browse files Browse the repository at this point in the history
Feature/tclune/#3406 cleanup
  • Loading branch information
pchakraborty authored Feb 12, 2025
2 parents 487ed13 + dca7dfa commit c493089
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 50 deletions.
12 changes: 6 additions & 6 deletions generic3g/ComponentSpecParser/parse_var_specs.F90
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,19 @@ subroutine parse_state_specs(var_specs, hconfig, state_intent, timestep, refTime
dependencies = to_dependencies(attributes, _RC)

esmf_state_intent = to_esmf_state_intent(state_intent)
var_spec = VariableSpec(esmf_state_intent, short_name=short_name, &
itemtype=itemtype, &
service_items=service_items, &
standard_name=standard_name, &
var_spec = make_VariableSpec(esmf_state_intent, short_name=short_name, &
units=units, &
itemtype=itemtype, &
typekind=typekind, &
default_value=default_value, &
vertical_dim_spec=vertical_dim_spec, &
ungridded_dims=ungridded_dims, &
default_value=default_value, &
service_items=service_items, &
standard_name=standard_name, &
dependencies=dependencies, &
accumulation_type=accumulation_type, &
timestep=timestep, &
refTime=refTime)
refTime=refTime, _RC)

if (allocated(units)) deallocate(units)
if (allocated(standard_name)) deallocate(standard_name)
Expand Down
18 changes: 11 additions & 7 deletions generic3g/MAPL_Generic.F90
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module mapl3g_Generic
use :: mapl3g_OuterMetaComponent, only: get_outer_meta
use :: mapl3g_ChildSpec, only: ChildSpec
use :: mapl3g_ComponentSpec, only: ComponentSpec
use :: mapl3g_VariableSpec, only: VariableSpec
use :: mapl3g_VariableSpec, only: VariableSpec, make_VariableSpec
use :: mapl3g_GriddedComponentDriver, only: GriddedComponentDriver
use :: mapl3g_UngriddedDims, only: UngriddedDims
use :: mapl3g_Validation, only: is_valid_name
Expand Down Expand Up @@ -435,7 +435,7 @@ subroutine add_spec_explicit(gridcomp, state_intent, unusable, short_name, stand
integer :: status
type(VariableSpec) :: var_spec

var_spec = VariableSpec( &
var_spec = make_VariableSpec( &
state_intent=state_intent, &
short_name=short_name, &
standard_name=standard_name, &
Expand Down Expand Up @@ -485,7 +485,7 @@ subroutine add_import_spec_legacy(gc, short_name, long_name, &
typekind = to_typekind(precision)
end if

var_spec = VariableSpec( &
var_spec = make_VariableSpec( &
state_intent=ESMF_STATEINTENT_IMPORT, &
short_name=short_name, &
typekind=typekind, &
Expand Down Expand Up @@ -568,11 +568,13 @@ subroutine add_export_spec(gridcomp, unusable, short_name, standard_name, units,
integer :: status
type(OuterMetaComponent), pointer :: outer_meta
type(ComponentSpec), pointer :: component_spec
type(VariableSpec) :: var_spec

call MAPL_GridCompGetOuterMeta(gridcomp, outer_meta, _RC)
component_spec => outer_meta%get_component_spec()
call component_spec%var_specs%push_back(VariableSpec(ESMF_STATEINTENT_EXPORT, &
short_name=short_name, standard_name=standard_name))
var_spec = make_VariableSpec(ESMF_STATEINTENT_EXPORT, short_name=short_name, &
standard_name=standard_name, _RC)
call component_spec%var_specs%push_back(var_spec)

_RETURN(ESMF_SUCCESS)
end subroutine add_export_spec
Expand All @@ -588,14 +590,16 @@ subroutine add_internal_spec(gridcomp, unusable, short_name, standard_name, unit
integer :: status
type(OuterMetaComponent), pointer :: outer_meta
type(ComponentSpec), pointer :: component_spec
type(VariableSpec) :: var_spec

call MAPL_GridCompGetOuterMeta(gridcomp, outer_meta, _RC)
component_spec => outer_meta%get_component_spec()
call component_spec%var_specs%push_back(VariableSpec( &
var_spec = make_VariableSpec( &
ESMF_STATEINTENT_INTERNAL, &
short_name=short_name, &
standard_name=standard_name, &
units=units))
units=units, _RC)
call component_spec%var_specs%push_back(var_spec)

_RETURN(ESMF_SUCCESS)
_UNUSED_DUMMY(unusable)
Expand Down
30 changes: 9 additions & 21 deletions generic3g/specs/VariableSpec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module mapl3g_VariableSpec
use mapl3g_TypekindAspect
use mapl3g_UngriddedDimsAspect
use mapl3g_AttributesAspect
use mapl3g_BracketClassAspect
use mapl3g_FrequencyAspect
use mapl3g_UngriddedDims
use mapl3g_VerticalDimSpec
Expand All @@ -31,6 +32,7 @@ module mapl3g_VariableSpec
private

public :: VariableSpec
public :: make_VariableSpec

! This type provides components that might be needed for _any_
! state item. This is largely to support legacy interfaces, but it
Expand All @@ -46,33 +48,25 @@ module mapl3g_VariableSpec
character(:), allocatable :: standard_name
type(ESMF_StateItem_Flag) :: itemtype = MAPL_STATEITEM_FIELD
type(StringVector), allocatable :: service_items
character(:), allocatable :: substate
real, allocatable :: default_value
type(StringVector) :: attributes
integer, allocatable :: bracket_size

! Geometry
type(VerticalDimSpec) :: vertical_dim_spec = VERTICAL_DIM_UNKNOWN ! none, center, edge
type(HorizontalDimsSpec) :: horizontal_dims_spec = HORIZONTAL_DIMS_GEOM ! none, geom
type(StringVector) :: dependencies
contains
procedure :: make_virtualPt
procedure :: make_dependencies
end type VariableSpec

interface VariableSpec
module procedure :: new_VariableSpec
end interface VariableSpec

contains

function new_VariableSpec( &
function make_VariableSpec( &
state_intent, short_name, unusable, standard_name, geom, &
units, substate, itemtype, typekind, vertical_dim_spec, ungridded_dims, default_value, &
units, itemtype, typekind, vertical_dim_spec, ungridded_dims, default_value, &
service_items, attributes, &
bracket_size, &
dependencies, regrid_param, horizontal_dims_spec, &
accumulation_type, timeStep, refTime) result(var_spec)
accumulation_type, timeStep, refTime, rc) result(var_spec)

type(VariableSpec) :: var_spec
type(ESMF_StateIntent_Flag), intent(in) :: state_intent
Expand All @@ -84,7 +78,6 @@ function new_VariableSpec( &
type(ESMF_StateItem_Flag), optional, intent(in) :: itemtype
type(StringVector), optional :: service_items
character(*), optional, intent(in) :: units
character(*), optional, intent(in) :: substate
type(ESMF_TypeKind_Flag), optional, intent(in) :: typekind
type(VerticalDimSpec), optional, intent(in) :: vertical_dim_spec
type(UngriddedDims), optional, intent(in) :: ungridded_dims
Expand All @@ -97,6 +90,7 @@ function new_VariableSpec( &
character(len=*), optional, intent(in) :: accumulation_type
type(ESMF_TimeInterval), optional, intent(in) :: timestep
type(ESMF_Time), optional, intent(in) :: refTime
integer, optional, intent(out) :: rc

type(ESMF_RegridMethod_Flag), allocatable :: regrid_method
type(EsmfRegridderParam) :: regrid_param_
Expand All @@ -112,40 +106,34 @@ function new_VariableSpec( &

call var_spec%aspects%insert(UNITS_ASPECT_ID, UnitsAspect(units))

regrid_param_ = get_regrid_param(regrid_param, standard_name)
call var_spec%aspects%insert(VERTICAL_GRID_ASPECT_ID, &
VerticalGridAspect(vertical_dim_spec=vertical_dim_spec, geom=geom))

regrid_param_ = get_regrid_param(regrid_param, standard_name)
call var_spec%aspects%insert(GEOM_ASPECT_ID, GeomAspect(geom, regrid_param_, horizontal_dims_spec))

call var_spec%aspects%insert(UNGRIDDED_DIMS_ASPECT_ID, UngriddedDimsAspect(ungridded_dims))
call var_spec%aspects%insert(ATTRIBUTES_ASPECT_ID, AttributesAspect(attributes))
call var_spec%aspects%insert(TYPEKIND_ASPECT_ID, TypekindAspect(typekind))

call var_spec%aspects%insert(FREQUENCY_ASPECT_ID, FrequencyAspect(timestep=timestep, refTime=refTime, accumulation_type=accumulation_type))

_SET_OPTIONAL(standard_name)
_SET_OPTIONAL(itemtype)

_SET_OPTIONAL(substate)
_SET_OPTIONAL(service_items)
_SET_OPTIONAL(default_value)
_SET_OPTIONAL(vertical_dim_spec)
_SET_OPTIONAL(attributes)
_SET_OPTIONAL(bracket_size)
_SET_OPTIONAL(dependencies)

_RETURN(_SUCCESS)
_UNUSED_DUMMY(unusable)
end function new_VariableSpec
end function make_VariableSpec


function make_virtualPt(this) result(v_pt)
type(VirtualConnectionPt) :: v_pt
class(VariableSpec), intent(in) :: this
v_pt = VirtualConnectionPt(this%state_intent, this%short_name)
if (allocated(this%substate)) then
v_pt = v_pt%add_comp_name(this%substate)
end if
end function make_virtualPt

function make_dependencies(this, rc) result(dependencies)
Expand Down
12 changes: 2 additions & 10 deletions generic3g/specs/make_itemSpec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ module mapl3g_make_itemSpec
use mapl3g_WildcardClassAspect
use mapl3g_ServiceClassAspect
use mapl3g_BracketClassAspect

!# use mapl3g_FieldSpec, only: FieldSpec
!# use mapl3g_ServiceSpec, only: ServiceSpec
!# use mapl3g_WildcardSpec, only: WildcardSpec
!# use mapl3g_BracketSpec, only: BracketSpec
!# use mapl3g_StateSpec, only: StateSpec
!# use mapl3g_InvalidSpec, only: InvalidSpec
use mapl3g_StateRegistry, only: StateRegistry
use mapl_ErrorHandling
use esmf, only: ESMF_STATEINTENT_INTERNAL, operator(==)
Expand All @@ -43,9 +36,8 @@ function make_itemSpec(variable_spec, registry, rc) result(item_spec)
type(VirtualConnectionPt) :: v_pt
type(StateItemExtension), pointer :: primary

class(ClassAspect), allocatable :: class_aspect, ref_class_aspect
type(StateItemSpec), target:: ref_spec
type(AspectMap), target :: ref_aspects, aspects
class(ClassAspect), allocatable :: class_aspect
type(AspectMap), target :: aspects

select case (variable_spec%itemtype%ot)
case (MAPL_STATEITEM_FIELD%ot)
Expand Down
2 changes: 1 addition & 1 deletion generic3g/tests/MockAspect.F90
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function MockItemSpec(value, state_intent, short_name, typekind, units, mirror,
units_ = 'barn'
if (present(units)) units_ = units

var_spec = VariableSpec(state_intent=state_intent_, short_name=short_name_, typekind=typekind, units=units_)
var_spec = make_VariableSpec(state_intent=state_intent_, short_name=short_name_, typekind=typekind, units=units_)
aspects => var_spec%aspects

mock_aspect = MockAspect(value, mirror_, time_dependent_, supports_conversion_)
Expand Down
4 changes: 2 additions & 2 deletions generic3g/tests/Test_BracketClassAspect.pf
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ contains
integer, parameter :: BRACKET_SIZE = 2
type(VerticalGridAspect) :: vert_aspect

var_spec = VariableSpec(itemtype=MAPL_STATEITEM_BRACKET, state_intent=ESMF_STATEINTENT_EXPORT, &
short_name='a', standard_name='A', geom=geom, units='m')
var_spec = make_VariableSpec(itemtype=MAPL_STATEITEM_BRACKET, state_intent=ESMF_STATEINTENT_EXPORT, &
short_name='a', standard_name='A', geom=geom, units='m', _RC)

aspects => var_spec%aspects
vert_aspect = VerticalGridAspect(BasicVerticalGrid(5))
Expand Down
4 changes: 2 additions & 2 deletions generic3g/tests/Test_ModelVerticalGrid.pf
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ contains
_FAIL("unsupported var name " // var_name)
end select

var_spec = VariableSpec(&
var_spec = make_VariableSpec(&
short_name=var_name, &
state_intent=ESMF_STATEINTENT_EXPORT, &
standard_name="air_pressure", &
units="hPa", &
vertical_dim_spec=vertical_dim_spec, &
default_value=3.)
default_value=3., _RC)
fld_spec = make_itemSpec(var_spec, r, rc=status); _VERIFY(status)
call fld_spec%set_geometry(geom=geom, vertical_grid=vgrid, _RC)
call fld_spec%create(_RC)
Expand Down
2 changes: 1 addition & 1 deletion gridcomps/History3G/HistoryCollectionGridComp_private.F90
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ subroutine add_specs(gridcomp, names, rc)
do while (ftn_iter /= ftn_end)
call ftn_iter%next()
short_name = ftn_iter%of()
varspec = VariableSpec(ESMF_STATEINTENT_IMPORT, short_name, vertical_dim_spec=VERTICAL_DIM_MIRROR)
varspec = make_VariableSpec(ESMF_STATEINTENT_IMPORT, short_name, vertical_dim_spec=VERTICAL_DIM_MIRROR, _RC)
call MAPL_AddSpec(gridcomp, varspec, _RC)
end do

Expand Down

0 comments on commit c493089

Please sign in to comment.