Test_AccumulatorAction.pf Source File


This file depends on

sourcefile~~test_accumulatoraction.pf~~EfferentGraph sourcefile~test_accumulatoraction.pf Test_AccumulatorAction.pf sourcefile~accumulator_action_test_common.f90 accumulator_action_test_common.F90 sourcefile~test_accumulatoraction.pf->sourcefile~accumulator_action_test_common.f90 sourcefile~accumulatoraction.f90 AccumulatorAction.F90 sourcefile~test_accumulatoraction.pf->sourcefile~accumulatoraction.f90 sourcefile~fieldutils.f90 FieldUtils.F90 sourcefile~test_accumulatoraction.pf->sourcefile~fieldutils.f90 sourcefile~accumulator_action_test_common.f90->sourcefile~fieldutils.f90 sourcefile~internalconstants.f90 InternalConstants.F90 sourcefile~accumulator_action_test_common.f90->sourcefile~internalconstants.f90 sourcefile~extensionaction.f90 ExtensionAction.F90 sourcefile~accumulatoraction.f90->sourcefile~extensionaction.f90 sourcefile~fieldpointerutilities.f90 FieldPointerUtilities.F90 sourcefile~accumulatoraction.f90->sourcefile~fieldpointerutilities.f90 sourcefile~fieldutilities.f90 FieldUtilities.F90 sourcefile~accumulatoraction.f90->sourcefile~fieldutilities.f90 sourcefile~accumulatoraction.f90->sourcefile~internalconstants.f90 sourcefile~mapl_exceptionhandling.f90 MAPL_ExceptionHandling.F90 sourcefile~accumulatoraction.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~fieldbinaryoperations.f90 FieldBinaryOperations.F90 sourcefile~fieldutils.f90->sourcefile~fieldbinaryoperations.f90 sourcefile~fieldblas.f90 FieldBLAS.F90 sourcefile~fieldutils.f90->sourcefile~fieldblas.f90 sourcefile~fieldutils.f90->sourcefile~fieldpointerutilities.f90 sourcefile~fieldunaryfunctions.f90 FieldUnaryFunctions.F90 sourcefile~fieldutils.f90->sourcefile~fieldunaryfunctions.f90 sourcefile~fieldutils.f90->sourcefile~fieldutilities.f90 sourcefile~errorhandling.f90 ErrorHandling.F90 sourcefile~extensionaction.f90->sourcefile~errorhandling.f90 sourcefile~fieldbinaryoperations.f90->sourcefile~fieldpointerutilities.f90 sourcefile~fieldbinaryoperations.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~fieldblas.f90->sourcefile~fieldpointerutilities.f90 sourcefile~fieldblas.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~fieldpointerutilities.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~fieldunaryfunctions.f90->sourcefile~fieldpointerutilities.f90 sourcefile~fieldunaryfunctions.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~fieldutilities.f90->sourcefile~fieldpointerutilities.f90 sourcefile~fieldutilities.f90->sourcefile~errorhandling.f90 sourcefile~fieldinfo.f90 FieldInfo.F90 sourcefile~fieldutilities.f90->sourcefile~fieldinfo.f90 sourcefile~infoutilities.f90 InfoUtilities.F90 sourcefile~fieldutilities.f90->sourcefile~infoutilities.f90 sourcefile~keywordenforcer.f90 KeywordEnforcer.F90 sourcefile~fieldutilities.f90->sourcefile~keywordenforcer.f90 sourcefile~lu_bound.f90 LU_Bound.F90 sourcefile~fieldutilities.f90->sourcefile~lu_bound.f90 sourcefile~ungriddeddims.f90 UngriddedDims.F90 sourcefile~fieldutilities.f90->sourcefile~ungriddeddims.f90 sourcefile~mapl_exceptionhandling.f90->sourcefile~errorhandling.f90 sourcefile~mapl_throw.f90 MAPL_Throw.F90 sourcefile~mapl_exceptionhandling.f90->sourcefile~mapl_throw.f90 sourcefile~errorhandling.f90->sourcefile~mapl_throw.f90 sourcefile~fieldinfo.f90->sourcefile~errorhandling.f90 sourcefile~fieldinfo.f90->sourcefile~infoutilities.f90 sourcefile~fieldinfo.f90->sourcefile~keywordenforcer.f90 sourcefile~fieldinfo.f90->sourcefile~ungriddeddims.f90 sourcefile~mapl_esmf_infokeys.f90 MAPL_ESMF_InfoKeys.F90 sourcefile~fieldinfo.f90->sourcefile~mapl_esmf_infokeys.f90 sourcefile~verticalstaggerloc.f90 VerticalStaggerLoc.F90 sourcefile~fieldinfo.f90->sourcefile~verticalstaggerloc.f90 sourcefile~infoutilities.f90->sourcefile~errorhandling.f90 sourcefile~infoutilities.f90->sourcefile~keywordenforcer.f90 sourcefile~infoutilities.f90->sourcefile~mapl_esmf_infokeys.f90 sourcefile~ungriddeddims.f90->sourcefile~errorhandling.f90 sourcefile~ungriddeddims.f90->sourcefile~infoutilities.f90 sourcefile~ungriddeddims.f90->sourcefile~lu_bound.f90 sourcefile~ungriddeddims.f90->sourcefile~mapl_esmf_infokeys.f90 sourcefile~ungriddeddim.f90 UngriddedDim.F90 sourcefile~ungriddeddims.f90->sourcefile~ungriddeddim.f90 sourcefile~ungriddeddimvector.f90 UngriddedDimVector.F90 sourcefile~ungriddeddims.f90->sourcefile~ungriddeddimvector.f90

Source Code

#include "MAPL_TestErr.h"
#include "unused_dummy.H"
module Test_AccumulatorAction
   use mapl3g_AccumulatorAction
   use accumulator_action_test_common
   use esmf
   use funit
   use MAPL_FieldUtils
   implicit none

contains

   @Test
   subroutine test_construct_AccumulatorAction()
      type(AccumulatorAction) :: acc

      @assertFalse(acc%update_calculated, 'updated_calculated .TRUE.')
      @assertFalse(acc%initialized(), 'initialized .TRUE.')

   end subroutine test_construct_AccumulatorAction

   @Test
   subroutine test_initialize()
      type(AccumulatorAction) :: acc
      type(ESMF_State) :: importState, exportState
      type(ESMF_Clock) :: clock
      integer :: status
      logical :: equals_expected_value 

      call initialize_objects(importState, exportState, clock, ESMF_TYPEKIND_R4, _RC)
      call acc%initialize(importState, exportState, clock, _RC)
      @assertTrue(acc%initialized(), 'initialized .FALSE.')
      equals_expected_value = FieldIsConstant(acc%accumulation_field, acc%CLEAR_VALUE_R4, _RC)
      @assertTrue(equals_expected_value, 'accumulation_field was not cleared.')
      call destroy_objects(importState, exportState, clock, _RC)

   end subroutine test_initialize

   @Test
   subroutine test_invalidate()
      type(AccumulatorAction) :: acc
      type(ESMF_State) :: importState, exportState
      type(ESMF_Clock) :: clock
      integer :: status
      type(ESMF_Field) :: import_field
      real(kind=R4), parameter :: invalidate_value = 4.0_R4
      logical :: equals_expected_value

      call initialize_objects(importState, exportState, clock, ESMF_TYPEKIND_R4, _RC)
      call acc%initialize(importState, exportState, clock, _RC)
      call get_field(importState, import_field, _RC)
      call FieldSet(import_field, invalidate_value, _RC)
      call acc%invalidate(importState, exportState, clock, _RC)
      @assertFalse(acc%update_calculated, 'update_calculated .TRUE.')
      equals_expected_value = FieldIsConstant(acc%accumulation_field, invalidate_value, _RC)
      @assertTrue(equals_expected_value, 'accumulation_field not equal to invalidate_value')
      call acc%invalidate(importState, exportState, clock, _RC)
      @assertFalse(acc%update_calculated, 'update_calculated .TRUE.')
      equals_expected_value = FieldIsConstant(acc%accumulation_field, 2*invalidate_value, _RC)
      @assertTrue(equals_expected_value, 'accumulation_field .FALSE.')
      call destroy_objects(importState, exportState, clock, _RC)

   end subroutine test_invalidate

   @Test
   subroutine test_update()
      type(AccumulatorAction) :: acc
      type(ESMF_State) :: importState, exportState
      type(ESMF_Clock) :: clock
      integer :: status
      type(ESMF_Field) :: import_field, export_field
      real(kind=R4), parameter :: invalidate_value = 4.0_R4
      real(kind=R4) :: update_value
      logical :: equals_expected_value

      call initialize_objects(importState, exportState, clock, ESMF_TYPEKIND_R4, _RC)
      call acc%initialize(importState, exportState, clock, _RC)
      call get_field(importState, import_field, _RC)
      call FieldSet(import_field, invalidate_value, _RC)
      call acc%invalidate(importState, exportState, clock, _RC)
      call acc%update(importState, exportState, clock, _RC)
      update_value = invalidate_value
      @assertTrue(acc%update_calculated, 'update_calculated .FALSE.')
      equals_expected_value = FieldIsConstant(acc%accumulation_field, acc%CLEAR_VALUE_R4, _RC)
      @assertTrue(equals_expected_value, 'accumulation_field was not cleared.')
      equals_expected_value = FieldIsConstant(acc%result_field, update_value, _RC)
      @assertTrue(equals_expected_value, 'result_field not equal to update_value')
      call get_field(exportState, export_field, _RC)
      equals_expected_value = FieldIsConstant(export_field, update_value, _RC)
      @assertTrue(equals_expected_value, 'export_field not equal to update_value')

      call acc%invalidate(importState, exportState, clock, _RC)
      call acc%invalidate(importState, exportState, clock, _RC)
      call acc%update(importState, exportState, clock, _RC)
      update_value = 2 * invalidate_value
      @assertTrue(acc%update_calculated, 'update_calculated .FALSE')
      equals_expected_value = FieldIsConstant(acc%accumulation_field, acc%CLEAR_VALUE_R4, _RC)
      @assertTrue(equals_expected_value, 'accumulation_field was not cleared.')
      equals_expected_value = FieldIsConstant(acc%result_field, update_value, _RC)
      @assertTrue(equals_expected_value, 'result_field not equal to update_value.')
      call get_field(exportState, export_field, _RC)
      equals_expected_value = FieldIsConstant(export_field, update_value, _RC)
      @assertTrue(equals_expected_value, 'export_field not equal to update_value')
      call destroy_objects(importState, exportState, clock, _RC)

   end subroutine test_update

   @Test
   subroutine test_accumulate()
      type(AccumulatorAction) :: acc
      type(ESMF_State) :: importState, exportState
      type(ESMF_Clock) :: clock
      integer :: status
      type(ESMF_Field) :: update_field
      type(ESMF_TypeKind_Flag) :: typekind
      logical :: matches_expected
      real(kind=ESMF_KIND_R4), parameter :: value_r4 = 3.0_ESMF_KIND_R4

      typekind = ESMF_TYPEKIND_R4
      call initialize_objects(importState, exportState, clock, typekind, _RC)
      call acc%initialize(importState, exportState, clock, _RC)
      call initialize_field(update_field, typekind=typekind, _RC)
      call FieldSet(update_field, value_r4, _RC)
      call acc%accumulate(update_field, _RC)
      matches_expected = FieldIsConstant(acc%accumulation_field, value_r4, _RC)
      @assertTrue(matches_expected, 'accumulation_field not equal to value_r4')
      call ESMF_FieldDestroy(update_field, _RC)
      call destroy_objects(importState, exportState, clock, _RC)

   end subroutine test_accumulate

   @Test
   subroutine test_clear()
      type(AccumulatorAction) :: acc
      type(ESMF_State) :: importState, exportState
      type(ESMF_Clock) :: clock
      integer :: status
      logical :: is_expected_value
      real(kind=ESMF_KIND_R4), parameter :: TEST_VALUE = 2.0_ESMF_KIND_R4

      call initialize_objects(importState, exportState, clock, ESMF_TYPEKIND_R4, _RC)
      call acc%initialize(importState, exportState, clock, _RC)
      call FieldSet(acc%accumulation_field, TEST_VALUE, _RC)
      call acc%clear(_RC)
      is_expected_value = FieldIsConstant(acc%accumulation_field, acc%CLEAR_VALUE_R4, _RC)
      @assertTrue(is_expected_value, 'accumulation_field was not cleared.')
      call destroy_objects(importState, exportState, clock, _RC)

   end subroutine test_clear

   @Test
   subroutine test_accumulate_R4()
      type(AccumulatorAction) :: acc
      type(ESMF_State) :: importState, exportState
      type(ESMF_Clock) :: clock
      integer :: status
      real(kind=R4), parameter :: INITIAL_VALUE = 2.0_R4
      real(kind=R4) :: update_value = 3.0_R4
      real(kind=R4) :: expected_value
      type(ESMF_Field) :: update_field
      logical :: field_is_expected_value

      call initialize_objects(importState, exportState, clock, ESMF_TYPEKIND_R4, _RC)
      call acc%initialize(importState, exportState, clock, _RC)
      call initialize_field(update_field, typekind=typekind, _RC)
      call FieldSet(update_field, update_value, _RC)
      call FieldSet(acc%accumulation_field, INITIAL_VALUE, _RC)
      call acc%accumulate_R4(update_field, _RC)
      expected_value = INITIAL_VALUE + update_value
      field_is_expected_value = FieldIsConstant(acc%accumulation_field, expected_value, _RC)
      @assertTrue(field_is_expected_value, 'accumulation_field not equal to expected_value.')
      call acc%accumulate_R4(update_field, _RC)
      expected_value = expected_value + update_value
      field_is_expected_value = FieldIsConstant(acc%accumulation_field, expected_value, _RC)
      @assertTrue(field_is_expected_value, 'accumulation_field not equal to expected_value.')
      call ESMF_FieldDestroy(update_field, _RC)
      call destroy_objects(importState, exportState, clock, _RC)

   end subroutine test_accumulate_R4

end module Test_AccumulatorAction