Skip to content

Commit fb9a555

Browse files
committed
Filter out data gridcomps from running. Also use the macros _GET/SET_NAMED_PRIVATE_STATE for the internal private state
1 parent 91cb551 commit fb9a555

File tree

1 file changed

+53
-66
lines changed

1 file changed

+53
-66
lines changed

ESMF/GOCART2G_GridComp/GOCART2G_GridCompMod.F90

Lines changed: 53 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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_GridCompGetChildrenNames, 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,18 @@ subroutine Run1 (gc, import, export, clock, RC)
484470
!DESCRIPTION: Run method
485471
!EOP
486472
class(logger_t), pointer :: logger
487-
integer :: status
473+
type(StringVector) :: children
474+
character(len=:), allocatable :: child_name
475+
integer :: iter, status
488476

489477
call MAPL_GridCompGet(gc, logger=logger, _RC)
490478
call logger%info("Run1: starting...")
491-
call MAPL_GridCompRunChildren(gc, phase_name="Run1", _RC)
479+
children = MAPL_GridCompGetChildrenNames(gc, _RC)
480+
do iter = 1, children%size()
481+
child_name = children%of(iter)
482+
if ((index(child_name, "data")) /= 0) cycle
483+
call MAPL_GridCompRunChild(gc, child_name, phase_name="Run0", _RC)
484+
end do
492485
call logger%info("Run1: ...complete")
493486

494487
_RETURN(_SUCCESS)
@@ -515,7 +508,6 @@ subroutine Run2 (gc, import, export, clock, rc)
515508

516509
type(ESMF_Grid) :: grid
517510
type (GOCART_State), pointer :: self
518-
type (wrap_) :: wrap
519511
real, pointer, dimension(:,:) :: lats
520512

521513
! ! Dust - ACG will generate this once we add DU's export states as GOCART's import
@@ -578,26 +570,25 @@ subroutine Run2 (gc, import, export, clock, rc)
578570
integer :: ind550, ind532
579571
integer :: i1, i2, j1, j2, km, k,kk
580572
class(logger_t), pointer :: logger
581-
integer :: n, w, status
573+
type(StringVector) :: children
574+
character(len=:), allocatable :: child_name
575+
integer :: n, w, iter, status
582576

583577
#include "GOCART2G_DeclarePointer___.h"
584578

585579
call MAPL_GridCompGet(gc, logger=logger, _RC)
586580
call logger%info("Run2: starting...")
581+
children = MAPL_GridCompGetChildrenNames(gc, _RC)
587582

588583
! 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)
584+
do iter = 1, children%size()
585+
child_name = children%of(iter)
586+
if ((index(child_name, "data")) /= 0) cycle
587+
call MAPL_GridCompRunChild(gc, child_name, phase_name="Run0", _RC)
588+
end do
597589

598-
! Get internal state
599-
call ESMF_UserCompGetInternalState(gc, "GOCART_State", wrap, _RC)
600-
self => wrap%ptr
590+
! Get private state
591+
_GET_NAMED_PRIVATE_STATE(gc, GOCART_State, PRIVATE_STATE, self)
601592

602593
#include "GOCART2G_GetPointer___.h"
603594
if(associated(totexttau)) totexttau = 0.
@@ -626,14 +617,11 @@ subroutine Run2 (gc, import, export, clock, rc)
626617
if(associated(pso4tot)) pso4tot(:,:,:) = 0.
627618

628619
! 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)
620+
do iter = 1, children%size()
621+
child_name = children%of(iter)
622+
if ((index(child_name, "data")) /= 0) cycle
623+
call MAPL_GridCompRunChild(gc, child_name, phase_name="Run2", _RC)
624+
end do
637625

638626
! Compute total aerosol diagnostic values for export
639627
call MAPL_GridCompGet(gc, grid=grid, _RC)
@@ -718,21 +706,21 @@ subroutine Run2 (gc, import, export, clock, rc)
718706
! Sea Salt
719707
do n = 1, size(self%SS%instances)
720708
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(:,:,:,:)
709+
if(associated(totexttau)) totexttau = totexttau + ssexttau
710+
if(associated(totstexttau)) totstexttau = totstexttau + ssstexttau
711+
if(associated(totscatau)) totscatau = totscatau + ssscatau
712+
if(associated(totstscatau)) totstscatau = totstscatau + ssstscatau
713+
if(associated(totextt25)) totextt25 = totextt25 + ssextt25
714+
if(associated(totscat25)) totscat25 = totscat25 + ssscat25
715+
if(associated(totexttfm)) totexttfm = totexttfm + ssexttfm
716+
if(associated(totscatfm)) totscatfm = totscatfm + ssscatfm
717+
if(associated(totextcoef)) totextcoef = totextcoef + ssextcoef
718+
if(associated(totextcoefrh20)) totextcoefrh20 = totextcoefrh20 + ssextcoefrh20
719+
if(associated(totextcoefrh80)) totextcoefrh80 = totextcoefrh80 + ssextcoefrh80
720+
if(associated(totscacoef)) totscacoef = totscacoef + ssscacoef
721+
if(associated(totscacoefrh20)) totscacoefrh20 = totscacoefrh20 + ssscacoefrh20
722+
if(associated(totscacoefrh80)) totscacoefrh80 = totscacoefrh80 + ssscacoefrh80
723+
if(associated(totbckcoef)) totbckcoef = totbckcoef + ssbckcoef
736724

737725
if(associated(pm) .and. associated(sssmass)) pm = pm + sssmass
738726
if(associated(pm25) .and. associated(sssmass25)) pm25 = pm25 + sssmass25
@@ -1212,7 +1200,6 @@ subroutine add_children__(gc, species, setservices, rc)
12121200
type(ESMF_HConfig) :: hconfig
12131201

12141202
do iter = 1, size(species%instances)
1215-
! species%instances(iter)%id = iter ! pchakrab: TODO - this needs to go
12161203
child_name = species%instances(iter)%name
12171204
config_file = species%name // "_instance_" // child_name // ".yaml"
12181205
hconfig = ESMF_HConfigCreate(filename=config_file, _RC)

0 commit comments

Comments
 (0)