From 1e994ce46de9b01235eaf097b115c845a655d6ba Mon Sep 17 00:00:00 2001 From: Darian Boggs Date: Thu, 19 Dec 2024 17:39:44 -0500 Subject: [PATCH 1/5] Changes to fix array problem --- generic3g/tests/Test_AccumulatorAction.pf | 4 ++-- generic3g/tests/Test_MaxAction.pf | 8 +++++--- generic3g/tests/Test_MeanAction.pf | 3 ++- generic3g/tests/Test_MinAction.pf | 2 +- generic3g/tests/accumulator_action_test_common.F90 | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/generic3g/tests/Test_AccumulatorAction.pf b/generic3g/tests/Test_AccumulatorAction.pf index 42fe674466bf..99d1f74f4eae 100644 --- a/generic3g/tests/Test_AccumulatorAction.pf +++ b/generic3g/tests/Test_AccumulatorAction.pf @@ -105,7 +105,7 @@ contains end subroutine test_update - @Test + !@Test subroutine test_accumulate() type(AccumulatorAction) :: acc type(ESMF_State) :: importState, exportState @@ -148,7 +148,7 @@ contains end subroutine test_clear - @Test + !@Test subroutine test_accumulate_R4() type(AccumulatorAction) :: acc type(ESMF_State) :: importState, exportState diff --git a/generic3g/tests/Test_MaxAction.pf b/generic3g/tests/Test_MaxAction.pf index 37049a924820..bcce9634e610 100644 --- a/generic3g/tests/Test_MaxAction.pf +++ b/generic3g/tests/Test_MaxAction.pf @@ -3,14 +3,16 @@ module Test_MaxAction use mapl3g_MaxAction use accumulator_action_test_common use esmf - use funit use MAPL_FieldUtils + use funit + use ESMF_TestMethod_mod implicit none contains - @Test - subroutine test_max_accumulate_R4() + !@Test(type=ESMF_TestMethod, npes=[1]) + subroutine test_max_accumulate_R4(this) + class(ESMF_TestMethod), intent(inout) :: this type(MaxAction) :: acc type(ESMF_State) :: importState, exportState type(ESMF_Clock) :: clock diff --git a/generic3g/tests/Test_MeanAction.pf b/generic3g/tests/Test_MeanAction.pf index 44ced2f22ec2..8e40d9de6827 100644 --- a/generic3g/tests/Test_MeanAction.pf +++ b/generic3g/tests/Test_MeanAction.pf @@ -100,6 +100,7 @@ contains end subroutine test_invalidate + !@test subroutine test_accumulate_mean_R4() type(MeanAction) :: acc type(ESMF_State) :: importState, exportState @@ -156,7 +157,7 @@ contains end subroutine test_initialize - @Test + !@Test subroutine test_accumulate_with_undef_some_steps() type(MeanAction) :: acc type(ESMF_State) :: importState, exportState diff --git a/generic3g/tests/Test_MinAction.pf b/generic3g/tests/Test_MinAction.pf index 0f9a3d151204..32b54c789451 100644 --- a/generic3g/tests/Test_MinAction.pf +++ b/generic3g/tests/Test_MinAction.pf @@ -9,7 +9,7 @@ module Test_MinAction contains - @Test + !@Test subroutine test_min_accumulate_R4() type(MinAction) :: acc type(ESMF_State) :: importState, exportState diff --git a/generic3g/tests/accumulator_action_test_common.F90 b/generic3g/tests/accumulator_action_test_common.F90 index 36b15c1ba1e7..fa46c5b256e4 100644 --- a/generic3g/tests/accumulator_action_test_common.F90 +++ b/generic3g/tests/accumulator_action_test_common.F90 @@ -88,7 +88,7 @@ subroutine initialize_objects(importState, exportState, clock, typekind, rc) call ESMF_TimeIntervalSet(timeStep, s=TIME_STEP, _RC) call ESMF_TimeSet(startTime, yy=START_TIME, _RC) clock = ESMF_ClockCreate(timeStep=timeStep, startTime=startTime, _RC) - grid = ESMF_GridCreateNoPeriDimUfrm(maxIndex=MAX_INDEX, minCornerCoord=MIN_CORNER_COORD, maxCornerCoord=MAX_CORNER_COORD, _RC) + grid = ESMF_GridCreate(regDecomp = [1, 1], maxIndex=MAX_INDEX, _RC) importField = ESMF_FieldCreate(grid=grid, typekind=typekind, _RC) exportField = ESMF_FieldCreate(grid=grid, typekind=typekind, _RC) importState = ESMF_StateCreate(stateIntent=ESMF_STATEINTENT_IMPORT, fieldList=[importField], name='import', _RC) From 8bc8235e85eb8906edceff17d51256010ec63e26 Mon Sep 17 00:00:00 2001 From: Darian Boggs Date: Thu, 19 Dec 2024 17:48:59 -0500 Subject: [PATCH 2/5] consolodate grid creation in subroutine --- .../tests/accumulator_action_test_common.F90 | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/generic3g/tests/accumulator_action_test_common.F90 b/generic3g/tests/accumulator_action_test_common.F90 index fa46c5b256e4..873b6e9c21ed 100644 --- a/generic3g/tests/accumulator_action_test_common.F90 +++ b/generic3g/tests/accumulator_action_test_common.F90 @@ -14,6 +14,7 @@ module accumulator_action_test_common integer(kind=ESMF_KIND_I4), parameter :: TIME_STEP = 1 integer(kind=ESMF_KIND_I4), parameter :: START_TIME = 3000 integer, parameter :: MAX_INDEX(2) = [4, 4] + integer, parameter :: REG_DECOMP = [1, 1] real(kind=ESMF_KIND_R8), parameter :: MIN_CORNER_COORD(2) = [0.0_R8, 0.0_R8] real(kind=ESMF_KIND_R8), parameter :: MAX_CORNER_COORD(2) = [4.0_R8, 4.0_R8] type(ESMF_TypeKind_Flag), parameter :: typekind = ESMF_TYPEKIND_R4 @@ -45,6 +46,16 @@ elemental subroutine set_undef(t) end subroutine set_undef + subroutine create_grid(grid, rc) + type(ESMF_Grid), optional, intent(inout) :: grid + integer, optional, intent(out) :: rc + integer :: status + + grid = ESMF_GridCreate(regDecomp=REG_DECOMP, maxIndex=MAX_INDEX, _RC) + _RETURN(_SUCCESS) + + end subroutine create_grid + subroutine initialize_field(field, typekind, grid, rc) type(ESMF_Field), intent(inout) :: field type(ESMF_TypeKind_Flag), intent(in) :: typekind @@ -62,8 +73,7 @@ subroutine initialize_field(field, typekind, grid, rc) end if if(.not. grid_created) then - grid_ = ESMF_GridCreateNoPeriDimUfrm(maxIndex=MAX_INDEX, & - & minCornerCoord=MIN_CORNER_COORD, maxCornerCoord=MAX_CORNER_COORD, _RC) + call create_grid(grid_, _RC) end if field = ESMF_FieldCreate(grid=grid_, typekind=typekind, _RC) @@ -88,7 +98,7 @@ subroutine initialize_objects(importState, exportState, clock, typekind, rc) call ESMF_TimeIntervalSet(timeStep, s=TIME_STEP, _RC) call ESMF_TimeSet(startTime, yy=START_TIME, _RC) clock = ESMF_ClockCreate(timeStep=timeStep, startTime=startTime, _RC) - grid = ESMF_GridCreate(regDecomp = [1, 1], maxIndex=MAX_INDEX, _RC) + call create_grid(grid, _RC) importField = ESMF_FieldCreate(grid=grid, typekind=typekind, _RC) exportField = ESMF_FieldCreate(grid=grid, typekind=typekind, _RC) importState = ESMF_StateCreate(stateIntent=ESMF_STATEINTENT_IMPORT, fieldList=[importField], name='import', _RC) From e3b6480e87ecf8e0b2550e9501bf5ff348086125 Mon Sep 17 00:00:00 2001 From: Darian Boggs Date: Fri, 20 Dec 2024 17:54:20 -0500 Subject: [PATCH 3/5] initialize_field use grid from accumulation_field --- generic3g/tests/Test_AccumulatorAction.pf | 43 ++++++++++------- generic3g/tests/Test_MaxAction.pf | 8 ++-- generic3g/tests/Test_MeanAction.pf | 8 ++-- generic3g/tests/Test_MinAction.pf | 12 +++-- .../tests/accumulator_action_test_common.F90 | 48 +++++++++++-------- 5 files changed, 69 insertions(+), 50 deletions(-) diff --git a/generic3g/tests/Test_AccumulatorAction.pf b/generic3g/tests/Test_AccumulatorAction.pf index 99d1f74f4eae..8a81aa563a21 100644 --- a/generic3g/tests/Test_AccumulatorAction.pf +++ b/generic3g/tests/Test_AccumulatorAction.pf @@ -1,17 +1,18 @@ #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 + use pfunit + use ESMF_TestMethod_mod implicit none contains - @Test - subroutine test_construct_AccumulatorAction() + @Test(type=ESMF_TestMethod, npes=[1]) + subroutine test_construct_AccumulatorAction(this) + class(ESMF_TestMethod), intent(inout) :: this type(AccumulatorAction) :: acc @assertFalse(acc%update_calculated, 'updated_calculated .TRUE.') @@ -19,8 +20,9 @@ contains end subroutine test_construct_AccumulatorAction - @Test - subroutine test_initialize() + @Test(type=ESMF_TestMethod, npes=[1]) + subroutine test_initialize(this) + class(ESMF_TestMethod), intent(inout) :: this type(AccumulatorAction) :: acc type(ESMF_State) :: importState, exportState type(ESMF_Clock) :: clock @@ -36,8 +38,9 @@ contains end subroutine test_initialize - @Test - subroutine test_invalidate() + @Test(type=ESMF_TestMethod, npes=[1]) + subroutine test_invalidate(this) + class(ESMF_TestMethod), intent(inout) :: this type(AccumulatorAction) :: acc type(ESMF_State) :: importState, exportState type(ESMF_Clock) :: clock @@ -62,8 +65,9 @@ contains end subroutine test_invalidate - @Test - subroutine test_update() + @Test(type=ESMF_TestMethod, npes=[1]) + subroutine test_update(this) + class(ESMF_TestMethod), intent(inout) :: this type(AccumulatorAction) :: acc type(ESMF_State) :: importState, exportState type(ESMF_Clock) :: clock @@ -105,8 +109,9 @@ contains end subroutine test_update - !@Test - subroutine test_accumulate() + @Test(type=ESMF_TestMethod, npes=[1]) + subroutine test_accumulate(this) + class(ESMF_TestMethod), intent(inout) :: this type(AccumulatorAction) :: acc type(ESMF_State) :: importState, exportState type(ESMF_Clock) :: clock @@ -119,7 +124,7 @@ contains 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 initialize_field(update_field, acc%accumulation_field, _RC) call FieldSet(update_field, value_r4, _RC) call acc%accumulate(update_field, _RC) matches_expected = FieldIsConstant(acc%accumulation_field, value_r4, _RC) @@ -129,8 +134,9 @@ contains end subroutine test_accumulate - @Test - subroutine test_clear() + @Test(type=ESMF_TestMethod, npes=[1]) + subroutine test_clear(this) + class(ESMF_TestMethod), intent(inout) :: this type(AccumulatorAction) :: acc type(ESMF_State) :: importState, exportState type(ESMF_Clock) :: clock @@ -148,8 +154,9 @@ contains end subroutine test_clear - !@Test - subroutine test_accumulate_R4() + @Test(type=ESMF_TestMethod, npes=[1]) + subroutine test_accumulate_R4(this) + class(ESMF_TestMethod), intent(inout) :: this type(AccumulatorAction) :: acc type(ESMF_State) :: importState, exportState type(ESMF_Clock) :: clock @@ -162,7 +169,7 @@ contains 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 initialize_field(update_field, acc%accumulation_field, _RC) call FieldSet(update_field, update_value, _RC) call FieldSet(acc%accumulation_field, INITIAL_VALUE, _RC) call acc%accumulate_R4(update_field, _RC) diff --git a/generic3g/tests/Test_MaxAction.pf b/generic3g/tests/Test_MaxAction.pf index bcce9634e610..b57ab67d3161 100644 --- a/generic3g/tests/Test_MaxAction.pf +++ b/generic3g/tests/Test_MaxAction.pf @@ -4,13 +4,13 @@ module Test_MaxAction use accumulator_action_test_common use esmf use MAPL_FieldUtils - use funit + use pfunit use ESMF_TestMethod_mod implicit none contains - !@Test(type=ESMF_TestMethod, npes=[1]) + @Test(type=ESMF_TestMethod, npes=[1]) subroutine test_max_accumulate_R4(this) class(ESMF_TestMethod), intent(inout) :: this type(MaxAction) :: acc @@ -29,7 +29,7 @@ contains call set_undef(undef_value) call initialize_objects(importState, exportState, clock, tk, _RC) call acc%initialize(importState, exportState, clock, _RC) - call initialize_field(update_field, typekind=tk, _RC) + call initialize_field(update_field, acc%accumulation_field, _RC) call assign_fptr(acc%accumulation_field, accPtr, _RC) call assign_fptr(update_field, upPtr, _RC) n = size(upPtr) @@ -38,7 +38,7 @@ contains upPtr(i:n) = [UPDATE_VALUE, undef_value, UPDATE_VALUE, UPDATE_VALUE+ACCUMULATED_VALUE] expected = [UPDATE_VALUE, ACCUMULATED_VALUE, ACCUMULATED_VALUE, UPDATE_VALUE+ACCUMULATED_VALUE] call acc%accumulate_R4(update_field, _RC) - @assertEqual(expected, accPtr, 'accumulated_field not equal to expected values') + @assertEqual(expected, accPtr, 'accumulation_field not equal to expected values') call ESMF_FieldDestroy(update_field, _RC) call destroy_objects(importState, exportState, clock, _RC) diff --git a/generic3g/tests/Test_MeanAction.pf b/generic3g/tests/Test_MeanAction.pf index 8e40d9de6827..cf6624feff38 100644 --- a/generic3g/tests/Test_MeanAction.pf +++ b/generic3g/tests/Test_MeanAction.pf @@ -100,7 +100,7 @@ contains end subroutine test_invalidate - !@test + @Test subroutine test_accumulate_mean_R4() type(MeanAction) :: acc type(ESMF_State) :: importState, exportState @@ -118,7 +118,7 @@ contains call get_field(importState, importField, _RC) call FieldSet(importField, IMPORT_VALUE, _RC) call acc%initialize(importState, exportState, clock, _RC) - call initialize_field(update_field, typekind=ESMF_TYPEKIND_R4, _RC) + call initialize_field(update_field, acc%accumulation_field, _RC) call assign_fptr(update_field, upPtr, _RC) upPtr = UPDATE_VALUE @@ -157,7 +157,7 @@ contains end subroutine test_initialize - !@Test + @Test subroutine test_accumulate_with_undef_some_steps() type(MeanAction) :: acc type(ESMF_State) :: importState, exportState @@ -172,7 +172,7 @@ contains call initialize_objects(importState, exportState, clock, ESMF_TYPEKIND_R4, _RC) call acc%initialize(importState, exportState, clock, _RC) - call initialize_field(update_field, typekind=ESMF_TYPEKIND_R4, _RC) + call initialize_field(update_field, acc%accumulation_field, _RC) call assign_fptr(update_field, upPtr, _RC) upPtr = UPDATE_VALUE allocate(mask(size(upPtr))) diff --git a/generic3g/tests/Test_MinAction.pf b/generic3g/tests/Test_MinAction.pf index 32b54c789451..958cdf652adc 100644 --- a/generic3g/tests/Test_MinAction.pf +++ b/generic3g/tests/Test_MinAction.pf @@ -3,14 +3,16 @@ module Test_MinAction use mapl3g_MinAction use accumulator_action_test_common use esmf - use funit use MAPL_FieldUtils + use pfunit + use ESMF_TestMethod_mod implicit none contains - !@Test - subroutine test_min_accumulate_R4() + @Test(type=ESMF_TestMethod, npes=[1]) + subroutine test_min_accumulate_R4(this) + class(ESMF_TestMethod), intent(inout) :: this type(MinAction) :: acc type(ESMF_State) :: importState, exportState type(ESMF_Clock) :: clock @@ -27,7 +29,7 @@ contains call set_undef(undef_value) call initialize_objects(importState, exportState, clock, tk, _RC) call acc%initialize(importState, exportState, clock, _RC) - call initialize_field(update_field, typekind=tk, _RC) + call initialize_field(update_field, acc%accumulation_field, _RC) call assign_fptr(acc%accumulation_field, accPtr, _RC) call assign_fptr(update_field, upPtr, _RC) n = size(upPtr) @@ -36,7 +38,7 @@ contains upPtr(i:n) = [UPDATE_VALUE, undef_value, UPDATE_VALUE, UPDATE_VALUE+ACCUMULATED_VALUE] expected = [UPDATE_VALUE, ACCUMULATED_VALUE, UPDATE_VALUE, ACCUMULATED_VALUE] call acc%accumulate_R4(update_field, _RC) - @assertEqual(expected, accPtr, 'accumulated_field not equal to expected values') + @assertEqual(expected, accPtr, 'accumulation_field not equal to expected values') call ESMF_FieldDestroy(update_field, _RC) call destroy_objects(importState, exportState, clock, _RC) diff --git a/generic3g/tests/accumulator_action_test_common.F90 b/generic3g/tests/accumulator_action_test_common.F90 index 873b6e9c21ed..b616687facbe 100644 --- a/generic3g/tests/accumulator_action_test_common.F90 +++ b/generic3g/tests/accumulator_action_test_common.F90 @@ -1,6 +1,7 @@ #define _RETURN_(R, S) if(present(R)) R = S; return #define _RETURN(S) _RETURN_(rc, S) #define _SUCCESS 0 +#define _FAILURE _SUCCESS-1 #include "MAPL_TestErr.h" module accumulator_action_test_common use esmf @@ -14,10 +15,13 @@ module accumulator_action_test_common integer(kind=ESMF_KIND_I4), parameter :: TIME_STEP = 1 integer(kind=ESMF_KIND_I4), parameter :: START_TIME = 3000 integer, parameter :: MAX_INDEX(2) = [4, 4] - integer, parameter :: REG_DECOMP = [1, 1] - real(kind=ESMF_KIND_R8), parameter :: MIN_CORNER_COORD(2) = [0.0_R8, 0.0_R8] - real(kind=ESMF_KIND_R8), parameter :: MAX_CORNER_COORD(2) = [4.0_R8, 4.0_R8] - type(ESMF_TypeKind_Flag), parameter :: typekind = ESMF_TYPEKIND_R4 + integer, parameter :: REG_DECOMP(2) = [1, 1] + type(ESMF_TypeKind_Flag), parameter :: TYPEKIND = ESMF_TYPEKIND_R4 + + interface initialize_field + module procedure :: initialize_field_new + module procedure :: initialize_field_source + end interface initialize_field contains @@ -56,32 +60,38 @@ subroutine create_grid(grid, rc) end subroutine create_grid - subroutine initialize_field(field, typekind, grid, rc) + subroutine initialize_field_new(field, typekind, grid, rc) type(ESMF_Field), intent(inout) :: field type(ESMF_TypeKind_Flag), intent(in) :: typekind - type(ESMF_Grid), optional, intent(inout) :: grid + type(ESMF_Grid), optional, intent(out) :: grid integer, optional, intent(out) :: rc - type(ESMF_Grid) :: grid_ - logical :: grid_created + type(ESMF_Grid) :: grid_ integer :: status - grid_created = .FALSE. - if(present(grid)) then - grid_created = ESMF_GridIsCreated(grid, _RC) - if(grid_created) grid_ = grid - end if + call create_grid(grid_, _RC) + field = ESMF_FieldCreate(grid=grid_, typekind=typekind, _RC) + if(present(grid)) grid=grid_ + _RETURN(_SUCCESS) - if(.not. grid_created) then - call create_grid(grid_, _RC) - end if + end subroutine initialize_field_new - field = ESMF_FieldCreate(grid=grid_, typekind=typekind, _RC) + subroutine initialize_field_source(field, source, grid, rc) + type(ESMF_Field), intent(inout) :: field + type(ESMF_Field), intent(inout) :: source + type(ESMF_Grid), optional, intent(out) :: grid + integer, optional, intent(out) :: rc + + type(ESMF_TypeKind_Flag) :: typekind + type(ESMF_Grid) :: grid_ + integer :: status - if(present(grid)) grid = grid_ + call ESMF_FieldGet(source, grid=grid_, typekind=typekind, _RC) + field = ESMF_FieldCreate(grid=grid_, typekind=typekind, _RC) + if(present(grid)) grid=grid_ _RETURN(_SUCCESS) - end subroutine initialize_field + end subroutine initialize_field_source subroutine initialize_objects(importState, exportState, clock, typekind, rc) type(ESMF_State), intent(inout) :: importState, exportState From 68b03709b1df99024036a0fb8672b830117b9c84 Mon Sep 17 00:00:00 2001 From: Darian Boggs Date: Thu, 2 Jan 2025 14:34:08 -0500 Subject: [PATCH 4/5] Fixed bug with NAG for MaxAction as well as others --- generic3g/tests/Test_AccumulatorAction.pf | 41 ++++++++-- generic3g/tests/Test_MaxAction.pf | 2 +- generic3g/tests/Test_MeanAction.pf | 74 ++++++++++--------- generic3g/tests/Test_MinAction.pf | 2 +- .../tests/accumulator_action_test_common.F90 | 1 + 5 files changed, 79 insertions(+), 41 deletions(-) diff --git a/generic3g/tests/Test_AccumulatorAction.pf b/generic3g/tests/Test_AccumulatorAction.pf index 8a81aa563a21..9ac9b4cb3c05 100644 --- a/generic3g/tests/Test_AccumulatorAction.pf +++ b/generic3g/tests/Test_AccumulatorAction.pf @@ -162,24 +162,53 @@ contains 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), parameter :: UPDATE_VALUE = 3.0_R4 real(kind=R4) :: expected_value + real(kind=R4), pointer :: upPtr(:), accPtr(:) type(ESMF_Field) :: update_field logical :: field_is_expected_value + integer :: n + ! first accumulate call initialize_objects(importState, exportState, clock, ESMF_TYPEKIND_R4, _RC) call acc%initialize(importState, exportState, clock, _RC) call initialize_field(update_field, acc%accumulation_field, _RC) - call FieldSet(update_field, update_value, _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 + 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.') + @assertTrue(field_is_expected_value, 'accumulation_field not equal to expected_value. (first test)') + ! second accumulate call acc%accumulate_R4(update_field, _RC) - expected_value = expected_value + update_value + 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.') + @assertTrue(field_is_expected_value, 'accumulation_field not equal to expected_value. (second test)') + + ! one update point to undef + expected_value = UPDATE_VALUE + call acc%initialize(importState, exportState, clock, _RC) + call assign_fptr(update_field, upPtr, _RC) + call assign_fptr(acc%accumulation_field, accPtr, _RC) + n = size(upPtr) + call set_undef(upPtr(n)) + call acc%accumulate_R4(update_field, _RC) + @assertTrue(undef(accPtr(n)), 'invalid point is not UNDEF.') + @assertTrue(all(pack(accPtr, .not. undef(accPtr)) == expected_value), 'valid point not equal to expected value. (update undef)') + + ! one accumulation point to undef + call acc%initialize(importState, exportState, clock, _RC) + call assign_fptr(update_field, upPtr, _RC) + upPtr = UPDATE_VALUE + call assign_fptr(acc%accumulation_field, accPtr, _RC) + accPtr = INITIAL_VALUE + n = size(accPtr) + call set_undef(accPtr(n)) + call acc%accumulate_R4(update_field, _RC) + expected_value = INITIAL_VALUE + UPDATE_VALUE + @assertTrue(undef(accPtr(n)), 'invalid point is not UNDEF.') + @assertTrue(all(pack(accPtr, .not. undef(accPtr)) == expected_value), 'valid point not equal to expected value. (accumulation undef)') + call ESMF_FieldDestroy(update_field, _RC) call destroy_objects(importState, exportState, clock, _RC) diff --git a/generic3g/tests/Test_MaxAction.pf b/generic3g/tests/Test_MaxAction.pf index b57ab67d3161..b3995e7643b3 100644 --- a/generic3g/tests/Test_MaxAction.pf +++ b/generic3g/tests/Test_MaxAction.pf @@ -38,7 +38,7 @@ contains upPtr(i:n) = [UPDATE_VALUE, undef_value, UPDATE_VALUE, UPDATE_VALUE+ACCUMULATED_VALUE] expected = [UPDATE_VALUE, ACCUMULATED_VALUE, ACCUMULATED_VALUE, UPDATE_VALUE+ACCUMULATED_VALUE] call acc%accumulate_R4(update_field, _RC) - @assertEqual(expected, accPtr, 'accumulation_field not equal to expected values') + @assertEqual(expected, accPtr(i:n), 'accumulation_field not equal to expected values') call ESMF_FieldDestroy(update_field, _RC) call destroy_objects(importState, exportState, clock, _RC) diff --git a/generic3g/tests/Test_MeanAction.pf b/generic3g/tests/Test_MeanAction.pf index cf6624feff38..7ddc76a6b72a 100644 --- a/generic3g/tests/Test_MeanAction.pf +++ b/generic3g/tests/Test_MeanAction.pf @@ -1,17 +1,18 @@ #include "MAPL_TestErr.h" module Test_MeanAction - use mapl3g_MeanAction use accumulator_action_test_common use esmf - use funit + use pfunit use MAPL_FieldUtils + use ESMF_TestMethod_mod implicit none contains - @Test - subroutine test_calculate_mean_R4() + @Test(type=ESMF_TestMethod, npes=[1]) + subroutine test_calculate_mean_R4(this) + class(ESMF_TestMethod), intent(inout) :: this type(MeanAction) :: acc type(ESMF_State) :: importState, exportState type(ESMF_Clock) :: clock @@ -46,11 +47,13 @@ contains call acc%calculate_mean_R4(_RC) @assertTrue(all(pack(fptr, mask) == MEAN), 'Some valid points not equal to MEAN') @assertTrue(undef(fptr(n)), 'mean at point was not UNDEF') + call destroy_objects(importState, exportState, clock, _RC) end subroutine test_calculate_mean_R4 - @Test - subroutine test_clear() + @Test(type=ESMF_TestMethod, npes=[1]) + subroutine test_clear(this) + class(ESMF_TestMethod), intent(inout) :: this type(MeanAction) :: acc type(ESMF_State) :: importState, exportState type(ESMF_Clock) :: clock @@ -71,8 +74,9 @@ contains end subroutine test_clear - @Test - subroutine test_invalidate() + @Test(type=ESMF_TestMethod, npes=[1]) + subroutine test_invalidate(this) + class(ESMF_TestMethod), intent(inout) :: this type(MeanAction) :: acc type(ESMF_State) :: importState, exportState type(ESMF_Clock) :: clock @@ -97,50 +101,51 @@ contains counter_is_set = all(fptr == N) @assertTrue(counter_is_set, 'counter_scalar not equal to N') call destroy_objects(importState, exportState, clock, _RC) + call ESMF_FieldDestroy(importField) end subroutine test_invalidate - @Test - subroutine test_accumulate_mean_R4() + @Test(type=ESMF_TestMethod, npes=[1]) + subroutine test_accumulate_mean_R4(this) + class(ESMF_TestMethod), intent(inout) :: this type(MeanAction) :: acc type(ESMF_State) :: importState, exportState type(ESMF_Clock) :: clock integer :: status - type(ESMF_Field) :: update_field - real(kind=ESMF_KIND_R4), pointer :: upPtr(:), accPtr(:) - real(kind=ESMF_KIND_R4), parameter :: IMPORT_VALUE = 2.0_R4 real(kind=ESMF_KIND_R4), parameter :: UPDATE_VALUE = 3.0_R4 - real(kind=ESMF_KIND_R4) :: result_value = IMPORT_VALUE + type(ESMF_Field) :: update_field + real(kind=ESMF_KIND_R4), pointer :: upPtr(:) => null() + real(kind=ESMF_KIND_R4), pointer :: accPtr(:) => null() + integer(kind=I4), pointer :: countPtr(:) => null() + integer(kind=I4), allocatable :: expected_count(:) integer :: n - type(ESMF_Field) :: importField call initialize_objects(importState, exportState, clock, ESMF_TYPEKIND_R4, _RC) - call get_field(importState, importField, _RC) - call FieldSet(importField, IMPORT_VALUE, _RC) call acc%initialize(importState, exportState, clock, _RC) call initialize_field(update_field, acc%accumulation_field, _RC) + ! set update field + call FieldSet(update_field, UPDATE_VALUE, _RC) call assign_fptr(update_field, upPtr, _RC) - upPtr = UPDATE_VALUE - - ! update_field not undef + ! set last element of update field to UNDEF + n = size(upPtr) + call set_undef(upPtr(n)) + ! run subroutine to test call acc%accumulate_R4(update_field, _RC) - result_value = result_value + UPDATE_VALUE call assign_fptr(acc%accumulation_field, accPtr, _RC) - @assertTrue(all(accPtr == result_value), 'accumulation_field not equal to expected value.') + call assign_fptr(acc%counter_field, countPtr, _RC) + allocate(expected_count(size(countPtr))) + expected_count = 1_I4 + expected_count(n) = 0_I4 + @assertEqual(expected_count, countPtr, 'Counts do not match.') - ! update_field undef at point - call FieldSet(importField, result_value, _RC) - call acc%initialize(importState, exportState, clock, _RC) - call acc%accumulate_R4(update_field, _RC) - result_value = result_value + UPDATE_VALUE - @assertTrue(undef(accPtr(n)), 'invalid point is not UNDEF') - @assertTrue(all(pack(accPtr, .not. undef(upPtr)) == result_value), 'valid point not equal to expected value.') + call ESMF_FieldDestroy(update_field) call destroy_objects(importState, exportState, clock, _RC) end subroutine test_accumulate_mean_R4 - @Test - subroutine test_initialize() + @Test(type=ESMF_TestMethod, npes=[1]) + subroutine test_initialize(this) + class(ESMF_TestMethod), intent(inout) :: this type(MeanAction) :: acc type(ESMF_State) :: importState, exportState type(ESMF_Clock) :: clock @@ -157,8 +162,9 @@ contains end subroutine test_initialize - @Test - subroutine test_accumulate_with_undef_some_steps() + @Test(type=ESMF_TestMethod, npes=[1]) + subroutine test_accumulate_with_undef_some_steps(this) + class(ESMF_TestMethod), intent(inout) :: this type(MeanAction) :: acc type(ESMF_State) :: importState, exportState type(ESMF_Clock) :: clock @@ -199,6 +205,8 @@ contains call assign_fptr(acc%accumulation_field, accPtr, _RC) @assertEqual(4*UPDATE_VALUE, accPtr(n), 'Missing point does not match.') @assertTrue(all(pack(accPtr, mask) == 5*UPDATE_VALUE), 'Other points do not match.') + call destroy_objects(importState, exportState, clock, _RC) + call ESMF_FieldDestroy(update_field) end subroutine test_accumulate_with_undef_some_steps diff --git a/generic3g/tests/Test_MinAction.pf b/generic3g/tests/Test_MinAction.pf index 958cdf652adc..de3b35897280 100644 --- a/generic3g/tests/Test_MinAction.pf +++ b/generic3g/tests/Test_MinAction.pf @@ -38,7 +38,7 @@ contains upPtr(i:n) = [UPDATE_VALUE, undef_value, UPDATE_VALUE, UPDATE_VALUE+ACCUMULATED_VALUE] expected = [UPDATE_VALUE, ACCUMULATED_VALUE, UPDATE_VALUE, ACCUMULATED_VALUE] call acc%accumulate_R4(update_field, _RC) - @assertEqual(expected, accPtr, 'accumulation_field not equal to expected values') + @assertEqual(expected, accPtr(i:n), 'accumulation_field not equal to expected values') call ESMF_FieldDestroy(update_field, _RC) call destroy_objects(importState, exportState, clock, _RC) diff --git a/generic3g/tests/accumulator_action_test_common.F90 b/generic3g/tests/accumulator_action_test_common.F90 index b616687facbe..273cfb87eb25 100644 --- a/generic3g/tests/accumulator_action_test_common.F90 +++ b/generic3g/tests/accumulator_action_test_common.F90 @@ -11,6 +11,7 @@ module accumulator_action_test_common integer, parameter :: R4 = ESMF_KIND_R4 integer, parameter :: R8 = ESMF_KIND_R8 + integer, parameter :: I4 = ESMF_KIND_I4 integer, parameter :: I8 = ESMF_KIND_I8 integer(kind=ESMF_KIND_I4), parameter :: TIME_STEP = 1 integer(kind=ESMF_KIND_I4), parameter :: START_TIME = 3000 From c8aa7f21d89bc9175394a84269461dc2da4aaa81 Mon Sep 17 00:00:00 2001 From: Darian Boggs Date: Thu, 2 Jan 2025 14:45:40 -0500 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3761e771be8c..ad9f81e8926c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Implemented workarounds to avoid needing `-dusty` for NAG. (Related PR in ESMA_CMake.) - Added constructor for DSO_SetServicesWrapper - Change macro in field/undo_function_overload.macro +- Fixed bug with AccumulatorAction and subtypes ## [Unreleased]