Test_SimpleLeafGridComp.pf Source File


This file depends on

sourcefile~~test_simpleleafgridcomp.pf~~EfferentGraph sourcefile~test_simpleleafgridcomp.pf Test_SimpleLeafGridComp.pf sourcefile~basicverticalgrid.f90 BasicVerticalGrid.F90 sourcefile~test_simpleleafgridcomp.pf->sourcefile~basicverticalgrid.f90 sourcefile~genericgridcomp.f90 GenericGridComp.F90 sourcefile~test_simpleleafgridcomp.pf->sourcefile~genericgridcomp.f90 sourcefile~mapl_generic.f90~2 MAPL_Generic.F90 sourcefile~test_simpleleafgridcomp.pf->sourcefile~mapl_generic.f90~2 sourcefile~outermetacomponent.f90 OuterMetaComponent.F90 sourcefile~test_simpleleafgridcomp.pf->sourcefile~outermetacomponent.f90 sourcefile~scratchpad.f90 scratchpad.F90 sourcefile~test_simpleleafgridcomp.pf->sourcefile~scratchpad.f90 sourcefile~usersetservices.f90 UserSetServices.F90 sourcefile~test_simpleleafgridcomp.pf->sourcefile~usersetservices.f90

Source Code

#include "MAPL_TestErr.h"
module Test_SimpleLeafGridComp
   use mapl3g_Generic
   use mapl3g_GenericPhases
   use mapl3g_UserSetServices
   use mapl3g_GenericGridComp, only: create_grid_comp
   use mapl3g_GenericGridComp, only: setServices
   use mapl3g_OuterMetaComponent, only: OuterMetaComponent
   use mapl3g_OuterMetaComponent, only: get_outer_meta
   use mapl3g_BasicVerticalGrid
   use esmf
   use nuopc
   use pFunit
   use scratchpad
   implicit none

contains

   subroutine setup(outer_gc, config, rc)
      type(ESMF_GridComp), intent(inout) :: outer_gc
      type(ESMF_HConfig), intent(in) :: config
      integer, intent(out) :: rc
      
      integer :: status, userRC
      type(ESMF_Time) :: t
      type(ESMF_TimeInterval) :: dt
      type(ESMF_Clock) :: clock

      call ESMF_TimeSet(t, h=0)
      call ESMF_TimeIntervalSet(dt, h=1)
      clock = ESMF_ClockCreate(dt, t)
      outer_gc = create_grid_comp('A', user_setservices('libsimple_leaf_gridcomp'), config, clock, rc=status)
      @assert_that(status, is(0))

      call ESMF_GridCompSetServices(outer_gc, setServices, userRC=userRC, rc=status)
      if (status /= 0) then
         rc = status
         return
      end if
      if (userRC /= 0) then
         rc = userRC
         return
      end if
      call clear_log()
      rc = 0

   end subroutine setup


   subroutine tearDown(outer_gc, hconfig)
      type(ESMF_GridComp), intent(inout) :: outer_gc
      type(ESMF_HConfig), intent(inout) :: hconfig

      call clear_log()
      call ESMF_HConfigDestroy(hconfig)

   end subroutine tearDown

   @test(npes=[0])
   subroutine test_wasrun_1(this)
      class(MpiTestMethod), intent(inout) :: this

      type(ESMF_HConfig) :: config
      integer :: status, userRC
      type(ESMF_GridComp) :: outer_gc

      config = ESMF_HConfigCreate(content='{}', rc=status)
      call setup(outer_gc, config, status)
      @assert_that('DSO problem', status, is(0))

      call ESMF_GridCompRun(outer_gc, userRC=userRC, phase=GENERIC_RUN_USER, rc=status)
      @assert_that(status, is(0))
      @assert_that(userRC, is(0))
      @assertEqual("wasRun_A", log)

      call teardown(outer_gc, config)

      if(.false.) print*,shape(this)
   end subroutine test_wasrun_1


   ! Verify that an optional run phase in the user comp can be
   ! exercised.  Note at this level, we cannot use the phase_name to
   ! specify the phase, so the unit test assumes the extra phase has
   ! index=2.   In real use cases, `run_child()` will be applied in
   ! which case the phase_name is available.
   
   @test(npes=[0])
   subroutine test_wasrun_extra(this)
      use scratchpad
      class(MpiTestMethod), intent(inout) :: this

      integer :: status
      type(ESMF_GridComp) :: outer_gc
      type(ESMF_HConfig) :: config

      config = ESMF_HConfigCreate(content='{}', rc=status)
      call setup(outer_gc, config, status)
      @assert_that(status, is(0))

      call ESMF_GridCompRun(outer_gc, phase=2, rc=status)
      @assert_that(status, is(0))
      @assertEqual("wasRun_extra_A", log)

      call teardown(outer_gc, config)
      if(.false.) print*,shape(this)
   end subroutine test_wasrun_extra

   @test(npes=[0])
   subroutine test_wasinit(this)
      use scratchpad
      class(MpiTestMethod), intent(inout) :: this

      integer :: status
      type(ESMF_GridComp) :: outer_gc
      type(ESMF_HConfig) :: config

      config = ESMF_HConfigCreate(content='{}', rc=status)
      call setup(outer_gc, config, status)
      @assert_that(status, is(0))

      call ESMF_GridCompInitialize(outer_gc, phase=GENERIC_INIT_USER, rc=status)
      @assert_that(status, is(0))
      @assertEqual("wasInit_A", log)

      call teardown(outer_gc, config)

      if(.false.) print*,shape(this)
   end subroutine test_wasinit
   
   @test(npes=[0])
   subroutine test_wasfinal(this)
      use scratchpad
      class(MpiTestMethod), intent(inout) :: this

      integer :: status
      type(ESMF_GridComp) :: outer_gc
      type(ESMF_HConfig) :: config

      config = ESMF_HConfigCreate(content='{}', rc=status)
      call setup(outer_gc, config, status)
      @assert_that(status, is(0))

      call ESMF_GridCompFinalize(outer_gc, phase=GENERIC_FINALIZE_USER, rc=status)
      @assert_that(status, is(0))
      @assertEqual("wasFinal_A", log)


      ! Note - do not need to call teardown, as we are
      ! finalizing ourselves.  But .. we do need to check that the
      ! user_gc has been finalized, and that the various internal states
      ! have been freed.

      if(.false.) print*,shape(this)
   end subroutine test_wasfinal

   @test(npes=[0])
   subroutine test_full_run_sequence(this)
      use scratchpad
      use iso_fortran_env
      class(MpiTestMethod), intent(inout) :: this
      type(ESMF_HConfig) :: config

      integer :: status, userrc
      type(ESMF_GridComp) :: outer_gc

      type(ESMF_Clock) :: clock
      type(ESMF_State) :: importState, exportState
      integer :: i
      type(ESMF_Field) :: f
      type(ESMF_Grid) :: grid
      type(BasicVerticalGrid) :: vertical_grid

      call NUOPC_FieldDictionarySetup('./scenarios/FieldDictionary.yml', rc=status)
      @assert_that(status, is(0))

      config = ESMF_HConfigCreate(filename='./scenarios/leaf_A.yaml')
      @assert_that(status, is(0))

      call setup(outer_gc, config, status)
      @assert_that(status, is(0))

      grid = ESMF_GridCreateNoPeriDim(maxIndex=[4,4], name='I_AM_GROOT', rc=status)
      @assert_that(status, is(0))
      vertical_grid = BasicVerticalGrid(4)
      call MAPL_GridCompSetGeom(outer_gc, grid, rc=status)
      @assert_that(status, is(0))
      call MAPL_GridCompSetVerticalGrid(outer_gc, vertical_grid, rc=status)
      @assert_that(status, is(0))

      importState = ESMF_StateCreate(stateIntent=ESMF_STATEINTENT_IMPORT, rc=status)
      @assert_that(status, is(0))
      exportState = ESMF_StateCreate(stateIntent=ESMF_STATEINTENT_EXPORT, rc=status)
      @assert_that(status, is(0))

      do i = 1, size(GENERIC_INIT_PHASE_SEQUENCE)
         associate (phase => GENERIC_INIT_PHASE_SEQUENCE(i))
           call ESMF_GridCompInitialize(outer_gc, &
                importState=importState, exportState=exportState, clock=clock, &
                phase=phase, userRC=userRC, rc=status)
         end associate
         @assert_that(userRC, is(0))
         @assert_that(status, is(0))
      end do

      call ESMF_StateGet(importState, 'I_1', f, rc=status)
      @assert_that(status, is(0))

      call ESMF_StateGet(exportState, 'E_1', f, rc=status)
      @assert_that(status, is(0))

      if(.false.) print*,shape(this)
   end subroutine test_full_run_sequence

   

end module Test_SimpleLeafGridComp