1- #include " MAPL_Generic .h"
1+ #include " MAPL .h"
22
33! BOP
44! MODULE: GOCART2G_GridCompMod - The GOCART 2nd Generation Aerosol Grid Component
@@ -11,17 +11,19 @@ module GOCART2G_GridCompMod
1111 use MAPL_Constants, only: MAPL_GRAV, MAPL_PI
1212
1313 use mapl3g_generic, only: MAPL_GridCompSetEntryPoint, MAPL_GridCompGet, MAPL_GridCompAddSpec
14- use mapl3g_generic, only: MAPL_GridCompAddChild, MAPL_GridCompAddConnectivity, MAPL_GridCompRunChildren
14+ use mapl3g_generic, only: MAPL_GridCompAddChild, MAPL_GridCompGetChildName, MAPL_GridCompRunChild
15+ use mapl3g_generic, only: MAPL_GridCompAddConnectivity
1516 use mapl3g_generic, only: MAPL_GridCompGetResource, MAPL_GridCompReexport
16- ! use mapl3g_generic, only: OuterMetaComponent, MAPL_GridCompGetOuterMeta
1717 use mapl3g_generic, only: MAPL_STATEITEM_STATE, MAPL_STATEITEM_FIELDBUNDLE
18+ use mapl3g_generic, only: MAPL_UserCompGetInternalState, MAPL_UserCompSetInternalState
1819 use mapl3g_RestartModes, only: MAPL_RESTART_SKIP
1920 use mapl3g_VerticalStaggerLoc, only: VERTICAL_STAGGER_NONE, VERTICAL_STAGGER_CENTER, VERTICAL_STAGGER_EDGE
2021 use mapl3g_FieldBundle_API, only: MAPL_FieldBundleAdd, MAPL_FieldBundleGet
2122 use mapl3g_State_API, only: MAPL_StateGetPointer
2223 use mapl3g_Geom_API, only: MAPL_GridGet
2324 use mapl3g_UngriddedDim, only: UngriddedDim
2425 use pflogger, only: logger_t = > logger
26+ use gftl2_StringVector, only: StringVector
2527
2628 use Chem_AeroGeneric
2729
@@ -61,9 +63,7 @@ module GOCART2G_GridCompMod
6163 real , allocatable :: wavelengths_vertint(:) ! wavelengths for vertically integrated aop [nm]
6264 end type GOCART_State
6365
64- type wrap_
65- type (GOCART_State), pointer :: ptr = > null ()
66- end type wrap_
66+ character (* ), parameter :: PRIVATE_STATE = " GOCART_STATE"
6767
6868 ! DESCRIPTION:
6969 !
@@ -100,7 +100,6 @@ subroutine SetServices(gc, rc)
100100 ! EOP
101101 type (ESMF_HConfig) :: hconfig
102102 type (GOCART_State), pointer :: self
103- type (wrap_) :: wrap
104103 integer , allocatable :: wavelengths_diagmie(:)
105104 ! logical :: use_threads
106105 class(logger_t), pointer :: logger
@@ -112,17 +111,16 @@ subroutine SetServices(gc, rc)
112111 call MAPL_GridCompGet(gc, logger= logger, _RC)
113112 call logger% info(" SetServices:: starting..." )
114113
115- ! Wrap internal state for storing in gc
116- allocate (self, _STAT)
117- wrap% ptr = > self
114+ ! Wrap gridcomp's private state and store in gc
115+ _SET_NAMED_PRIVATE_STATE(gc, GOCART_state, PRIVATE_STATE)
118116
119117 ! Set the Initialize, Run, Finalize entry points
120118 call MAPL_GridCompSetEntryPoint(gc, ESMF_Method_Initialize, Initialize, _RC)
121119 call MAPL_GridCompSetEntryPoint(gc, ESMF_Method_Run, Run1, phase_name= " Run1" , _RC)
122120 call MAPL_GridCompSetEntryPoint(gc, ESMF_Method_Run, Run2, phase_name= " Run2" , _RC)
123121
124- ! Store internal state in gc
125- call ESMF_UserCompSetInternalState (gc, " GOCART_State" , wrap, _RC )
122+ ! Retrieve the private state
123+ _GET_NAMED_PRIVATE_STATE (gc, GOCART_State, PRIVATE_STATE, self )
126124
127125 call MAPL_GridCompGetResource(gc, " wavelengths_for_profile_aop_in_nm" , self% wavelengths_profile, _RC)
128126 call MAPL_GridCompGetResource(gc, " wavelengths_for_vertically_integrated_aop_in_nm" , self% wavelengths_vertint, _RC)
@@ -314,13 +312,10 @@ subroutine Initialize (gc, import, export, clock, rc)
314312 type (ESMF_FieldBundle) :: aero_dp
315313 type (ESMF_Info) :: info
316314 type (GOCART_State), pointer :: self
317- type (wrap_) :: wrap
318- ! integer :: n_modes
319315 character (len= ESMF_MAXSTR), allocatable :: aero_aci_modes(:)
320316 real :: maxclean, ccntuning
321- integer :: im, jm, km
317+ integer :: im, jm, km, status
322318 class(logger_t), pointer :: logger
323- integer :: status
324319
325320 ! Get the target components name and set-up traceback handle.
326321 call MAPL_GridCompGet(gc, logger= logger, _RC)
@@ -330,15 +325,8 @@ subroutine Initialize (gc, import, export, clock, rc)
330325 call MAPL_GridCompGet(gc, geom= geom, grid= grid, num_levels= km, _RC)
331326 call MAPL_GridGet(grid, im= im, jm= jm, _RC)
332327
333- ! Get my internal state
334- call ESMF_UserCompGetInternalState(gc, " GOCART_State" , wrap, _RC)
335- self = > wrap% ptr
336-
337- ! CF = ESMF_ConfigCreate (_RC)
338- ! call ESMF_ConfigLoadFile (CF, "AGCM.rc", _RC) ! should the rc file be changed?
339-
340- ! ! Get children and their export states from my generic state
341- ! call MAPL_Get (MAPL, gcs=gcs, gex=gex, _RC )
328+ ! Get my private state
329+ _GET_NAMED_PRIVATE_STATE(gc, GOCART_State, PRIVATE_STATE, self)
342330
343331 ! Fill AERO_RAD, AERO_ACI, and AERO_DP with the children's states
344332 call ESMF_StateGet(export, " AERO" , aero, _RC)
@@ -405,9 +393,7 @@ subroutine Initialize (gc, import, export, clock, rc)
405393 " ss001 " , " ss002 " , " ss003 " , &
406394 " sulforg01" , " sulforg02" , " sulforg03" , &
407395 " bcphilic " , " ocphilic " , " brcphilic" ]
408- ! n_modes = size(aero_aci_modes)
409396
410- ! call ESMF_InfoSet(info, key="number_of_aerosol_modes", value=n_modes, _RC)
411397 call ESMF_InfoSet(info, key= " aerosol_modes" , values= aero_aci_modes, _RC)
412398
413399 ! max mixing ratio before switching to "polluted" size distributions
@@ -484,11 +470,16 @@ subroutine Run1 (gc, import, export, clock, RC)
484470 ! DESCRIPTION: Run method
485471 ! EOP
486472 class(logger_t), pointer :: logger
487- integer :: status
473+ character (len= :), allocatable :: child_name
474+ integer :: num_children, iter, status
488475
489- call MAPL_GridCompGet(gc, logger= logger, _RC)
476+ call MAPL_GridCompGet(gc, logger= logger, num_children = num_children, _RC)
490477 call logger% info(" Run1: starting..." )
491- call MAPL_GridCompRunChildren(gc, phase_name= " Run1" , _RC)
478+ do iter = 1 , num_children
479+ child_name = MAPL_GridCompGetChildName(gc, iter, _RC)
480+ if ((index (child_name, " data" )) /= 0 ) cycle
481+ call MAPL_GridCompRunChild(gc, child_name, phase_name= " Run1" , _RC)
482+ end do
492483 call logger% info(" Run1: ...complete" )
493484
494485 _RETURN(_SUCCESS)
@@ -515,7 +506,6 @@ subroutine Run2 (gc, import, export, clock, rc)
515506
516507 type (ESMF_Grid) :: grid
517508 type (GOCART_State), pointer :: self
518- type (wrap_) :: wrap
519509 real , pointer , dimension (:,:) :: lats
520510
521511 ! ! Dust - ACG will generate this once we add DU's export states as GOCART's import
@@ -578,26 +568,23 @@ subroutine Run2 (gc, import, export, clock, rc)
578568 integer :: ind550, ind532
579569 integer :: i1, i2, j1, j2, km, k,kk
580570 class(logger_t), pointer :: logger
581- integer :: n, w, status
571+ character (len= :), allocatable :: child_name
572+ integer :: n, w, num_children, iter, status
582573
583574#include " GOCART2G_DeclarePointer___.h"
584575
585- call MAPL_GridCompGet(gc, logger= logger, _RC)
576+ call MAPL_GridCompGet(gc, logger= logger, num_children = num_children, _RC)
586577 call logger% info(" Run2: starting..." )
587578
588579 ! Run zero Klid for children
589- ! pchakrab: TODO - how to exclude "data" versions of children??
590- ! do i = 1, size(gcs)
591- ! call ESMF_GridCompGet (gcs(i), NAME=child_name, _RC )
592- ! if ((index(child_name, 'data')) == 0) then ! only execute phase3 method if a computational instance
593- ! call ESMF_GridCompRun (gcs(i), importState=gim(i), exportState=gex(i), phase=3, clock=clock, _RC)
594- ! end if
595- ! end do
596- call MAPL_GridCompRunChildren(gc, phase_name= " Run0" , _RC)
580+ do iter = 1 , num_children
581+ child_name = MAPL_GridCompGetChildName(gc, iter, _RC)
582+ if ((index (child_name, " data" )) /= 0 ) cycle
583+ call MAPL_GridCompRunChild(gc, child_name, phase_name= " Run0" , _RC)
584+ end do
597585
598- ! Get internal state
599- call ESMF_UserCompGetInternalState(gc, " GOCART_State" , wrap, _RC)
600- self = > wrap% ptr
586+ ! Get private state
587+ _GET_NAMED_PRIVATE_STATE(gc, GOCART_State, PRIVATE_STATE, self)
601588
602589#include " GOCART2G_GetPointer___.h"
603590 if (associated (totexttau)) totexttau = 0 .
@@ -626,14 +613,11 @@ subroutine Run2 (gc, import, export, clock, rc)
626613 if (associated (pso4tot)) pso4tot(:,:,:) = 0 .
627614
628615 ! Run the children
629- ! do i = 1, size(gcs)
630- ! call ESMF_GridCompGet (gcs(i), NAME=child_name, _RC )
631- ! if ((index(child_name, 'data')) == 0) then ! only execute phase2 method if a computational instance
632- ! call ESMF_GridCompRun (gcs(i), importState=gim(i), exportState=gex(i), phase=2, clock=clock, _RC)
633- ! end if
634- ! end do
635- ! pchakrab: TODO - how to exclude "data" versions of children??
636- call MAPL_GridCompRunChildren(gc, phase_name= " Run2" , _RC)
616+ do iter = 1 , num_children
617+ child_name = MAPL_GridCompGetChildName(gc, iter, _RC)
618+ if ((index (child_name, " data" )) /= 0 ) cycle
619+ call MAPL_GridCompRunChild(gc, child_name, phase_name= " Run2" , _RC)
620+ end do
637621
638622 ! Compute total aerosol diagnostic values for export
639623 call MAPL_GridCompGet(gc, grid= grid, _RC)
@@ -718,21 +702,21 @@ subroutine Run2 (gc, import, export, clock, rc)
718702 ! Sea Salt
719703 do n = 1 , size (self% SS% instances)
720704 if ((self% SS% instances(n)% is_active) .and. (index (self% SS% instances(n)% name, " data" ) == 0 )) then
721- if (associated (totexttau)) totexttau(:,:,:) = totexttau(:,:,:) + ssexttau(:,:,:)
722- if (associated (totstexttau)) totstexttau(:,:,:) = totstexttau(:,:,:) + ssstexttau(:,:,:)
723- if (associated (totscatau)) totscatau(:,:,:) = totscatau(:,:,:) + ssscatau(:,:,:)
724- if (associated (totstscatau)) totstscatau(:,:,:) = totstscatau(:,:,:) + ssstscatau(:,:,:)
725- if (associated (totextt25)) totextt25(:,:,:) = totextt25(:,:,:) + ssextt25(:,:,:)
726- if (associated (totscat25)) totscat25(:,:,:) = totscat25(:,:,:) + ssscat25(:,:,:)
727- if (associated (totexttfm)) totexttfm(:,:,:) = totexttfm(:,:,:) + ssexttfm(:,:,:)
728- if (associated (totscatfm)) totscatfm(:,:,:) = totscatfm(:,:,:) + ssscatfm(:,:,:)
729- if (associated (totextcoef)) totextcoef(:,:,:,:) = totextcoef(:,:,:,:) + ssextcoef(:,:,:,:)
730- if (associated (totextcoefrh20)) totextcoefrh20(:,:,:,:) = totextcoefrh20(:,:,:,:) + ssextcoefrh20(:,:,:,:)
731- if (associated (totextcoefrh80)) totextcoefrh80(:,:,:,:) = totextcoefrh80(:,:,:,:) + ssextcoefrh80(:,:,:,:)
732- if (associated (totscacoef)) totscacoef(:,:,:,:) = totscacoef(:,:,:,:) + ssscacoef(:,:,:,:)
733- if (associated (totscacoefrh20)) totscacoefrh20(:,:,:,:) = totscacoefrh20(:,:,:,:) + ssscacoefrh20(:,:,:,:)
734- if (associated (totscacoefrh80)) totscacoefrh80(:,:,:,:) = totscacoefrh80(:,:,:,:) + ssscacoefrh80(:,:,:,:)
735- if (associated (totbckcoef)) totbckcoef(:,:,:,:) = totbckcoef(:,:,:,:) + ssbckcoef(:,:,:,:)
705+ if (associated (totexttau)) totexttau = totexttau + ssexttau
706+ if (associated (totstexttau)) totstexttau = totstexttau + ssstexttau
707+ if (associated (totscatau)) totscatau = totscatau + ssscatau
708+ if (associated (totstscatau)) totstscatau = totstscatau + ssstscatau
709+ if (associated (totextt25)) totextt25 = totextt25 + ssextt25
710+ if (associated (totscat25)) totscat25 = totscat25 + ssscat25
711+ if (associated (totexttfm)) totexttfm = totexttfm + ssexttfm
712+ if (associated (totscatfm)) totscatfm = totscatfm + ssscatfm
713+ if (associated (totextcoef)) totextcoef = totextcoef + ssextcoef
714+ if (associated (totextcoefrh20)) totextcoefrh20 = totextcoefrh20 + ssextcoefrh20
715+ if (associated (totextcoefrh80)) totextcoefrh80 = totextcoefrh80 + ssextcoefrh80
716+ if (associated (totscacoef)) totscacoef = totscacoef + ssscacoef
717+ if (associated (totscacoefrh20)) totscacoefrh20 = totscacoefrh20 + ssscacoefrh20
718+ if (associated (totscacoefrh80)) totscacoefrh80 = totscacoefrh80 + ssscacoefrh80
719+ if (associated (totbckcoef)) totbckcoef = totbckcoef + ssbckcoef
736720
737721 if (associated (pm) .and. associated (sssmass)) pm = pm + sssmass
738722 if (associated (pm25) .and. associated (sssmass25)) pm25 = pm25 + sssmass25
@@ -1212,7 +1196,6 @@ subroutine add_children__(gc, species, setservices, rc)
12121196 type (ESMF_HConfig) :: hconfig
12131197
12141198 do iter = 1 , size (species% instances)
1215- ! species%instances(iter)%id = iter ! pchakrab: TODO - this needs to go
12161199 child_name = species% instances(iter)% name
12171200 config_file = species% name // " _instance_" // child_name // " .yaml"
12181201 hconfig = ESMF_HConfigCreate(filename= config_file, _RC)
0 commit comments