Test_RegridderManager.pf Source File


This file depends on

sourcefile~~test_regriddermanager.pf~~EfferentGraph sourcefile~test_regriddermanager.pf Test_RegridderManager.pf sourcefile~mapl_abstractregridder.f90 MAPL_AbstractRegridder.F90 sourcefile~test_regriddermanager.pf->sourcefile~mapl_abstractregridder.f90 sourcefile~mockregridder.f90 MockRegridder.F90 sourcefile~test_regriddermanager.pf->sourcefile~mockregridder.f90 sourcefile~base_base.f90 Base_Base.F90 sourcefile~mapl_abstractregridder.f90->sourcefile~base_base.f90 sourcefile~constants.f90 Constants.F90 sourcefile~mapl_abstractregridder.f90->sourcefile~constants.f90 sourcefile~mapl_exceptionhandling.f90 MAPL_ExceptionHandling.F90 sourcefile~mapl_abstractregridder.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~mapl_keywordenforcer.f90 MAPL_KeywordEnforcer.F90 sourcefile~mapl_abstractregridder.f90->sourcefile~mapl_keywordenforcer.f90 sourcefile~mapl_memutils.f90 MAPL_MemUtils.F90 sourcefile~mapl_abstractregridder.f90->sourcefile~mapl_memutils.f90 sourcefile~regridderspec.f90 RegridderSpec.F90 sourcefile~mapl_abstractregridder.f90->sourcefile~regridderspec.f90 sourcefile~regridderspecroutehandlemap.f90 RegridderSpecRouteHandleMap.F90 sourcefile~mapl_abstractregridder.f90->sourcefile~regridderspecroutehandlemap.f90 sourcefile~mockregridder.f90->sourcefile~mapl_abstractregridder.f90 sourcefile~mockregridder.f90->sourcefile~mapl_keywordenforcer.f90 sourcefile~base_base.f90->sourcefile~constants.f90 sourcefile~base_base.f90->sourcefile~mapl_keywordenforcer.f90 sourcefile~mapl_range.f90 MAPL_Range.F90 sourcefile~base_base.f90->sourcefile~mapl_range.f90 sourcefile~maplgrid.f90 MaplGrid.F90 sourcefile~base_base.f90->sourcefile~maplgrid.f90 sourcefile~internalconstants.f90 InternalConstants.F90 sourcefile~constants.f90->sourcefile~internalconstants.f90 sourcefile~mathconstants.f90 MathConstants.F90 sourcefile~constants.f90->sourcefile~mathconstants.f90 sourcefile~physicalconstants.f90 PhysicalConstants.F90 sourcefile~constants.f90->sourcefile~physicalconstants.f90 sourcefile~mapl_errorhandling.f90 MAPL_ErrorHandling.F90 sourcefile~mapl_exceptionhandling.f90->sourcefile~mapl_errorhandling.f90 sourcefile~mapl_throw.f90 MAPL_Throw.F90 sourcefile~mapl_exceptionhandling.f90->sourcefile~mapl_throw.f90 sourcefile~mapl_memutils.f90->sourcefile~base_base.f90 sourcefile~mapl_memutils.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~mapl_comms.f90 MAPL_Comms.F90 sourcefile~mapl_memutils.f90->sourcefile~mapl_comms.f90 sourcefile~mapl_memutils.f90->sourcefile~mapl_errorhandling.f90 sourcefile~mapl_io.f90 MAPL_IO.F90 sourcefile~mapl_memutils.f90->sourcefile~mapl_io.f90 sourcefile~shmem.f90 Shmem.F90 sourcefile~mapl_memutils.f90->sourcefile~shmem.f90 sourcefile~regridderspec.f90->sourcefile~mapl_keywordenforcer.f90 sourcefile~regridderspec.f90->sourcefile~mapl_errorhandling.f90 sourcefile~mapl_gridmanager.f90 MAPL_GridManager.F90 sourcefile~regridderspec.f90->sourcefile~mapl_gridmanager.f90 sourcefile~regridmethods.f90 RegridMethods.F90 sourcefile~regridderspec.f90->sourcefile~regridmethods.f90 sourcefile~regridderspecroutehandlemap.f90->sourcefile~regridderspec.f90

Source Code

module Test_RegridderFactoryRegistry
   use pFUnit
   use ESMF
   use MAPL_RegridderFactoryRegistryMod
   use MAPL_RegridderSpecMod
   use MAPL_RegridderFactorySpecMod
   use MAPL_AbstractRegridderMod
   use MAPL_AbstractRegridderFactoryMod
   use MockRegridderMod
   use MockRegridderFactoryMod
   implicit none


contains

   @test
   subroutine test_retrieve_exists()
      type (ESMF_Grid), target :: g1_in, g1_out
      type (RegridderSpec) :: regridder_spec
      type (RegridderFactorySpec) :: factory_spec
      type (RegridderFactoryRegistry) :: registry

      class (AbstractRegridderFactory), pointer :: factory
      class (AbstractRegridder), allocatable :: regridder


      g1_in = ESMF_GridEmptyCreate()
      g1_out = ESMF_GridEmptyCreate()

      call ESMF_AttributeSet(g1_in, name='GridType', value='A')
      call ESMF_AttributeSet(g1_out, name='GridType', value='B')

      regridder_spec = RegridderSpec(g1_in, g1_out)
      factory_spec = RegridderFactorySpec(regridder_spec)

      factory => registry%at(factory_spec)
      @assertFalse(associated(factory))

      call registry%insert(factory_spec, MockRegridderFactory('A to B'))
      factory => registry%at(factory_spec)
      @assertTrue(associated(factory))

      allocate(regridder, source=factory%make_regridder(regridder_spec))
      select type (regridder)
      type is (MockRegridder)
         @assertEqual('A to B::A -> B', regridder%get_name())
      class default
         call throw('incorrect type of regridder returned')
      end select
      
   end subroutine test_retrieve_exists

   @test
   subroutine test_retrieve_multi()
      type (ESMF_Grid), target :: g_A, g_B, g_C
      type (RegridderSpec) :: regridder_spec
      type (RegridderFactorySpec) :: spec_AB, spec_BC, spec_CB
      type (RegridderFactoryRegistry) :: registry

      class (AbstractRegridderFactory), pointer :: factory
      class (AbstractRegridder), allocatable :: regridder


      g_A = ESMF_GridEmptyCreate()
      g_B = ESMF_GridEmptyCreate()
      g_C = ESMF_GridEmptyCreate()

      call ESMF_AttributeSet(g_A, name='GridType', value='A')
      call ESMF_AttributeSet(g_B, name='GridType', value='B')
      call ESMF_AttributeSet(g_C, name='GridType', value='C')

      regridder_spec = RegridderSpec(g_A, g_B)
      spec_AB = RegridderFactorySpec(regridder_spec)
      call registry%insert(spec_AB, MockRegridderFactory('A to B'))

      regridder_spec = RegridderSpec(g_B, g_C)
      spec_BC = RegridderFactorySpec(regridder_spec)
      call registry%insert(spec_BC, MockRegridderFactory('B to C'))
      
      regridder_spec = RegridderSpec(g_C, g_B)
      spec_CB = RegridderFactorySpec(regridder_spec)
      call registry%insert(spec_CB, MockRegridderFactory('C to B'))
      
      factory => registry%at(spec_AB)
      @assertTrue(associated(factory))

      regridder_spec = RegridderSpec(g_C, g_A)
      allocate(regridder, source=factory%make_regridder(regridder_spec))
      select type (regridder)
      type is (MockRegridder)
         @assertEqual('A to B::C -> A', regridder%get_name())
      class default
         call throw('incorrect type of regridder returned')
      end select
      deallocate(regridder)

      factory => registry%at(spec_BC)
      @assertTrue(associated(factory))

      allocate(regridder, source=factory%make_regridder(regridder_spec))
      select type (regridder)
      type is (MockRegridder)
         @assertEqual('B to C::C -> A', regridder%get_name())
      class default
         call throw('incorrect type of regridder returned')
      end select
      deallocate(regridder)

      factory => registry%at(spec_CB)
      @assertTrue(associated(factory))

      allocate(regridder, source=factory%make_regridder(regridder_spec))
      select type (regridder)
      type is (MockRegridder)
         @assertEqual('C to B::C -> A', regridder%get_name())
      class default
         call throw('incorrect type of regridder returned')
      end select
      deallocate(regridder)
      
   end subroutine test_retrieve_multi

   
end module Test_RegridderFactoryRegistry