#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