From b6a841ad103eb7db7fc814f51fea9f989a81ba00 Mon Sep 17 00:00:00 2001 From: Tom Clune Date: Fri, 23 Aug 2024 11:29:30 -0400 Subject: [PATCH] Further work on phase realignment. --- .../initialize_advertise.F90 | 3 +- .../initialize_modify_advertise.F90 | 22 ++++++++++++ generic3g/connection/ReexportConnection.F90 | 26 +++++++++----- generic3g/registry/StateRegistry.F90 | 12 +++++++ generic3g/specs/FieldSpec.F90 | 35 +++++++++++-------- generic3g/tests/scenarios/3d_specs/A.yaml | 6 ++-- generic3g/tests/scenarios/3d_specs/B.yaml | 7 ++-- .../scenarios/precision_extension_3d/A.yaml | 6 ++-- 8 files changed, 81 insertions(+), 36 deletions(-) diff --git a/generic3g/OuterMetaComponent/initialize_advertise.F90 b/generic3g/OuterMetaComponent/initialize_advertise.F90 index 081ccd066637..268cb6760400 100644 --- a/generic3g/OuterMetaComponent/initialize_advertise.F90 +++ b/generic3g/OuterMetaComponent/initialize_advertise.F90 @@ -95,7 +95,6 @@ subroutine advertise_variable(var_spec, registry, geom, vertical_grid, unusable, call item_spec%create(_RC) virtual_pt = var_spec%make_virtualPt() -!# call registry%add_item_spec(virtual_pt, item_spec) call registry%add_primary_spec(virtual_pt, item_spec) _RETURN(_SUCCESS) @@ -115,7 +114,7 @@ subroutine process_connections(this, rc) iter = this%component_spec%connections%begin() do while (iter /= e) c => iter%of() - call c%connect(this%registry, _RC) + call c%activate(this%registry, _RC) call iter%next() end do end associate diff --git a/generic3g/OuterMetaComponent/initialize_modify_advertise.F90 b/generic3g/OuterMetaComponent/initialize_modify_advertise.F90 index c998c04ed323..1513ffe91749 100644 --- a/generic3g/OuterMetaComponent/initialize_modify_advertise.F90 +++ b/generic3g/OuterMetaComponent/initialize_modify_advertise.F90 @@ -19,6 +19,8 @@ module recursive subroutine initialize_modify_advertise(this, importState, expor type(MultiState) :: outer_states, user_states call this%run_custom(ESMF_METHOD_INITIALIZE, PHASE_NAME, _RC) + call process_connections(this, _RC) + call this%registry%propagate_exports(_RC) user_states = this%user_gc_driver%get_states() call this%registry%add_to_states(user_states, mode='user', _RC) @@ -31,5 +33,25 @@ module recursive subroutine initialize_modify_advertise(this, importState, expor _RETURN(_SUCCESS) _UNUSED_DUMMY(unusable) end subroutine initialize_modify_advertise + + subroutine process_connections(this, rc) + class(OuterMetaComponent), intent(inout) :: this + integer, optional, intent(out) :: rc + + integer :: status + type(ConnectionVectorIterator) :: iter + class(Connection), pointer :: c + + associate (e => this%component_spec%connections%end()) + iter = this%component_spec%connections%begin() + do while (iter /= e) + c => iter%of() + call c%connect(this%registry, _RC) + call iter%next() + end do + end associate + + _RETURN(_SUCCESS) + end subroutine process_connections end submodule initialize_modify_advertise_smod diff --git a/generic3g/connection/ReexportConnection.F90 b/generic3g/connection/ReexportConnection.F90 index c352052986fc..1525bf31e804 100644 --- a/generic3g/connection/ReexportConnection.F90 +++ b/generic3g/connection/ReexportConnection.F90 @@ -67,7 +67,15 @@ recursive subroutine activate(this, registry, rc) integer, optional, intent(out) :: rc integer :: status + type(StateRegistry), pointer :: src_registry + type(ConnectionPt) :: src_pt + src_pt = this%get_source() + src_registry => registry%get_subregistry(src_pt) + _ASSERT(associated(src_registry), 'Unknown source registry') + + call this%connect_export_to_export(registry, src_registry, _RC) + _RETURN(_SUCCESS) end subroutine activate @@ -76,15 +84,15 @@ recursive subroutine connect(this, registry, rc) type(StateRegistry), target, intent(inout) :: registry integer, optional, intent(out) :: rc - integer :: status - type(StateRegistry), pointer :: src_registry - type(ConnectionPt) :: src_pt - - src_pt = this%get_source() - src_registry => registry%get_subregistry(src_pt) - _ASSERT(associated(src_registry), 'Unknown source registry') - - call this%connect_export_to_export(registry, src_registry, _RC) +!# integer :: status +!# type(StateRegistry), pointer :: src_registry +!# type(ConnectionPt) :: src_pt +!# +!# src_pt = this%get_source() +!# src_registry => registry%get_subregistry(src_pt) +!# _ASSERT(associated(src_registry), 'Unknown source registry') +!# +!# call this%connect_export_to_export(registry, src_registry, _RC) _RETURN(_SUCCESS) end subroutine connect diff --git a/generic3g/registry/StateRegistry.F90 b/generic3g/registry/StateRegistry.F90 index b466e593db8d..3cb6ac961e9c 100644 --- a/generic3g/registry/StateRegistry.F90 +++ b/generic3g/registry/StateRegistry.F90 @@ -488,6 +488,8 @@ subroutine propagate_exports_virtual_pt(this, subregistry_name, iter, rc) type(VirtualConnectionPt), pointer :: virtual_pt type(VirtualConnectionPt) :: new_virtual_pt type(ExtensionFamily), pointer :: family + integer :: n + type(VirtualPtFamilyMapIterator) :: new_iter virtual_pt => iter%first() _RETURN_UNLESS(virtual_pt%is_export()) @@ -496,6 +498,16 @@ subroutine propagate_exports_virtual_pt(this, subregistry_name, iter, rc) if (virtual_pt%get_comp_name() == '') then new_virtual_pt = VirtualConnectionPt(virtual_pt, comp_name=subregistry_name) end if + + ! TODO: Better logic would be the following line. But gFTL has + ! a missing TARGET attribute (bug) +!# n = this%family_map%erase(new_virtual_pt) + ! instead we do this: + associate(e => this%family_map%end()) + new_iter = this%family_map%find(new_virtual_pt) + new_iter = this%family_map%erase(new_iter, e) + end associate + call this%add_virtual_pt(new_virtual_pt, _RC) family => iter%second() call this%family_map%insert(new_virtual_pt, family) diff --git a/generic3g/specs/FieldSpec.F90 b/generic3g/specs/FieldSpec.F90 index 9cdaffec29dc..6ec4232bbb44 100644 --- a/generic3g/specs/FieldSpec.F90 +++ b/generic3g/specs/FieldSpec.F90 @@ -38,10 +38,26 @@ module mapl3g_FieldSpec public :: FieldSpec public :: new_FieldSpec_geom + ! Two FieldSpec's can be connected if: + ! 1) They only differ in the following components: + ! - geom (couple with Regridder) + ! - vertical_regrid (couple with VerticalRegridder) + ! - typekind (Copy) + ! - units (Convert) + ! - frequency_spec (tbd) + ! - halo width (tbd) + ! 2) They have the same values for + ! - ungridded_dims + ! - standard_name + ! - long_name + ! - regrid_param + ! - default_value + ! 3) The attributes of destination spec are a subset of the + ! attributes of the source spec. + type, extends(StateItemSpec) :: FieldSpec private - type(ESMF_Geom), allocatable :: geom class(VerticalGrid), allocatable :: vertical_grid type(VerticalDimSpec) :: vertical_dim_spec = VERTICAL_DIM_UNKNOWN @@ -62,6 +78,8 @@ module mapl3g_FieldSpec type(ESMF_Field) :: payload real, allocatable :: default_value + logical :: is_created = .false. + contains procedure :: create @@ -74,8 +92,6 @@ module mapl3g_FieldSpec procedure :: add_to_state procedure :: add_to_bundle - procedure :: check_complete - procedure :: extension_cost procedure :: make_extension @@ -200,6 +216,7 @@ subroutine create(this, rc) integer :: status this%payload = ESMF_FieldEmptyCreate(_RC) + this%is_created = .true. _RETURN(ESMF_SUCCESS) end subroutine create @@ -585,18 +602,6 @@ subroutine add_to_bundle(this, bundle, rc) _RETURN(_SUCCESS) end subroutine add_to_bundle - logical function check_complete(this, rc) - class(FieldSpec), intent(in) :: this - integer, intent(out), optional :: rc - - integer :: status - type(ESMF_FieldStatus_Flag) :: fstatus - - call ESMF_FieldGet(this%payload, status=fstatus, _RC) - check_complete = (fstatus == ESMF_FIELDSTATUS_COMPLETE) - - end function check_complete - integer function extension_cost(this, src_spec, rc) result(cost) class(FieldSpec), intent(in) :: this class(StateItemSpec), intent(in) :: src_spec diff --git a/generic3g/tests/scenarios/3d_specs/A.yaml b/generic3g/tests/scenarios/3d_specs/A.yaml index e6e7eb54044f..7327de1975cb 100644 --- a/generic3g/tests/scenarios/3d_specs/A.yaml +++ b/generic3g/tests/scenarios/3d_specs/A.yaml @@ -2,20 +2,20 @@ mapl: states: export: E_A1: - standard_name: 'A1 standard name' + standard_name: 'A1 standard name' units: 'barn' typekind: R4 default_value: 1. vertical_dim_spec: NONE E_A3: - standard_name: 'A3 standard name' + standard_name: 'A3 standard name' units: 'barn' typekind: R4 default_value: 7. vertical_dim_spec: NONE import: I_A2: - standard_name: 'B2 standard name' + standard_name: 'B2 standard name' units: 'barn' typekind: R4 default_value: 3. diff --git a/generic3g/tests/scenarios/3d_specs/B.yaml b/generic3g/tests/scenarios/3d_specs/B.yaml index 6bbb07858bc3..77ba1033ba1e 100644 --- a/generic3g/tests/scenarios/3d_specs/B.yaml +++ b/generic3g/tests/scenarios/3d_specs/B.yaml @@ -2,7 +2,7 @@ mapl: states: export: E_B2: - standard_name: 'B2 standard name' + standard_name: 'B2 standard name' units: 'barn' typekind: R4 default_value: 5. @@ -10,15 +10,14 @@ mapl: import: I_B1: - standard_name: 'I_B1 standard name' + standard_name: 'I_B1 standard name' units: 'barn' typekind: R4 default_value: 2. # expected to change vertical_dim_spec: NONE I_B3: - standard_name: 'I_B3 standard name' + standard_name: 'I_B3 standard name' units: 'barn' typekind: R4 default_value: 2. # expected to change vertical_dim_spec: NONE - diff --git a/generic3g/tests/scenarios/precision_extension_3d/A.yaml b/generic3g/tests/scenarios/precision_extension_3d/A.yaml index 471bdf2d07b4..4d29d14377c4 100644 --- a/generic3g/tests/scenarios/precision_extension_3d/A.yaml +++ b/generic3g/tests/scenarios/precision_extension_3d/A.yaml @@ -2,20 +2,20 @@ mapl: states: export: E_A1: - standard_name: 'A1 standard name' + standard_name: 'A1 standard name' units: 'barn' typekind: R4 default_value: 1. vertical_dim_spec: NONE E_A3: - standard_name: 'A3 standard name' + standard_name: 'A3 standard name' units: 'barn' typekind: R4 default_value: 7. vertical_dim_spec: NONE import: I_A2: - standard_name: 'B2 standard name' + standard_name: 'B2 standard name' units: 'barn' typekind: R8 default_value: 3.