11#include " MAPL.h"
22
33module mapl3g_VectorClassAspect
4+
45 use mapl3g_Field_API
56 use mapl3g_FieldBundle_API
67 use mapl3g_ActualConnectionPt
@@ -33,6 +34,7 @@ module mapl3g_VectorClassAspect
3334 use mapl_ErrorHandling
3435 use gftl2_StringVector
3536 use esmf
37+
3638 implicit none (type,external )
3739 private
3840
@@ -74,7 +76,6 @@ module mapl3g_VectorClassAspect
7476 procedure :: new_VectorClassAspect_basic
7577 end interface VectorClassAspect
7678
77-
7879contains
7980
8081 function new_VectorClassAspect_basic (short_names , component_specs , basis_kind ) result(aspect)
@@ -86,10 +87,8 @@ function new_VectorClassAspect_basic(short_names, component_specs, basis_kind) r
8687 aspect% short_names = short_names
8788 aspect% component_specs = component_specs
8889 aspect% basis_kind = basis_kind
89-
9090 end function new_VectorClassAspect_basic
9191
92-
9392 ! Should always be the same as for Field
9493 function get_aspect_order (this , goal_aspects , rc ) result(aspect_ids)
9594 type (AspectId), allocatable :: aspect_ids(:)
@@ -98,11 +97,10 @@ function get_aspect_order(this, goal_aspects, rc) result(aspect_ids)
9897 integer , optional , intent (out ) :: rc
9998
10099 integer :: status
101-
100+
102101 aspect_ids = this% component_specs(1 )% get_aspect_order(goal_aspects, _RC)
103102
104103 _RETURN(_SUCCESS)
105-
106104 _UNUSED_DUMMY(goal_aspects)
107105 end function get_aspect_order
108106
@@ -129,12 +127,12 @@ subroutine create(this, other_aspects, rc)
129127 type (ESMF_Info) :: info
130128
131129 this% payload = MAPL_FieldBundleCreate(fieldBundleType= FIELDBUNDLETYPE_VECTOR, _RC)
132-
130+
133131 call ESMF_InfoGetFromHost(this% payload, info, _RC)
134132 call MAPL_FieldBundleSet(this% payload, &
135- allocation_status= STATEITEM_ALLOCATION_CREATED, &
136- vector_basis_kind= this% basis_kind, &
137- _RC)
133+ allocation_status= STATEITEM_ALLOCATION_CREATED, &
134+ vector_basis_kind= this% basis_kind, &
135+ _RC)
138136
139137 _RETURN(ESMF_SUCCESS)
140138 _UNUSED_DUMMY(other_aspects)
@@ -181,7 +179,7 @@ subroutine update_payload(field_aspect, other_aspects, rc)
181179 type (esmf_Field), allocatable :: field
182180
183181 call field_aspect% get_payload(field= field, _RC)
184-
182+
185183 associate(e = > other_aspects% ftn_end())
186184 iter = other_aspects% ftn_begin()
187185 do while (iter /= e)
@@ -192,7 +190,6 @@ subroutine update_payload(field_aspect, other_aspects, rc)
192190 end associate
193191
194192 _RETURN(_SUCCESS)
195-
196193 end subroutine update_payload
197194
198195 subroutine destroy (this , rc )
@@ -239,27 +236,11 @@ subroutine connect_to_export(this, export, actual_pt, rc)
239236 call this% destroy(_RC) ! import is replaced by export/extension
240237 this% payload = export_% payload
241238
239+ ! mirror short names since they are required in add_to_state routine
240+ this% short_names = export_% short_names
241+
242242 _RETURN(_SUCCESS)
243243 _UNUSED_DUMMY(actual_pt)
244-
245- contains
246-
247- subroutine mirror (dst , src )
248- real , allocatable , intent (inout ) :: dst
249- real , allocatable , intent (in ) :: src
250-
251- if (.not. allocated (src)) return
252-
253- if (.not. allocated (dst)) then
254- dst = src
255- return
256- end if
257-
258- ! TODO: Problematic case: both allocated with different values.
259- if (dst /= src) then
260- end if
261- end subroutine mirror
262-
263244 end subroutine connect_to_export
264245
265246 function to_vectorclassaspect_from_poly (aspect , rc ) result(vector_aspect)
@@ -297,7 +278,7 @@ function make_transform(src, dst, other_aspects, rc) result(transform)
297278 class(StateItemAspect), intent (in ) :: dst
298279 type (AspectMap), target , intent (in ) :: other_aspects
299280 integer , optional , intent (out ) :: rc
300-
281+
301282 transform = NullTransform()
302283
303284 _RETURN(_SUCCESS)
@@ -332,13 +313,12 @@ subroutine add_to_state(this, multi_state, actual_pt, rc)
332313
333314 type (ESMF_FieldBundle) :: alias, existing_bundle
334315 type (esmf_StateItem_Flag) :: itemType
335- logical :: is_alias
336- integer :: status
337316 type (ESMF_State) :: state, substate
338- character (:), allocatable :: full_name, inner_name
339- integer :: idx
340- character (:), allocatable :: intent
341-
317+ type (ESMF_Field), allocatable :: field_list(:)
318+ logical :: is_alias
319+ character (:), allocatable :: full_name, inner_name, intent
320+ integer :: idx, status
321+
342322 intent = actual_pt% get_state_intent()
343323 call multi_state% get_state(state, intent , _RC)
344324
@@ -358,6 +338,13 @@ subroutine add_to_state(this, multi_state, actual_pt, rc)
358338 end if
359339 call ESMF_StateAddReplace(substate, [alias], _RC)
360340
341+ ! Also update the names of the components
342+ call MAPL_FieldBundleGet(this% payload, fieldList= field_list, _RC)
343+ if (size (field_list) > 0 ) then ! might be empty if import item
344+ call ESMF_FieldSet(field_list(1 ), name= trim (this% short_names% at(1 )), _RC)
345+ call ESMF_FieldSet(field_list(2 ), name= trim (this% short_names% at(2 )), _RC)
346+ end if
347+
361348 _RETURN(_SUCCESS)
362349 end subroutine add_to_state
363350
@@ -376,7 +363,7 @@ subroutine get_payload(this, unusable, field, bundle, state, rc)
376363 _UNUSED_DUMMY(field)
377364 _UNUSED_DUMMY(state)
378365 end subroutine get_payload
379-
366+
380367 function get_aspect_id () result(aspect_id)
381368 type (AspectId) :: aspect_id
382369 aspect_id = CLASS_ASPECT_ID
0 commit comments