Skip to content

Commit

Permalink
Merge pull request #3166 from GEOS-ESM/feature/wdboggs/accumulator_ad…
Browse files Browse the repository at this point in the history
…ditional_tests

Accumulator Additional Tests and Fixes
  • Loading branch information
tclune authored Nov 13, 2024
2 parents 854b175 + 6702570 commit 372d637
Show file tree
Hide file tree
Showing 12 changed files with 509 additions and 292 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added vertical and ungridded dimensions to output for History3G
- Create rank-agnostic representation of `ESMF_Field` objects as rank-3 array pointers.
- Add time accumulation for output from ESMF_Field objects.
- Add tests for time accumulation

### Changed

Expand Down
4 changes: 1 addition & 3 deletions generic3g/actions/AccumulatorAction.F90
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ subroutine initialize(this, importState, exportState, clock, rc)

call get_field(importState, import_field, _RC)
call get_field(exportState, export_field, _RC)
fields_are_conformable = FieldsAreConformable(import_field, export_field, _RC)
_ASSERT(fields_are_conformable, 'Import field and export field are not conformable.')

if(this%initialized()) then
call ESMF_FieldDestroy(this%accumulation_field, _RC)
Expand All @@ -77,8 +75,8 @@ subroutine initialize(this, importState, exportState, clock, rc)
this%result_field = ESMF_FieldCreate(export_field, _RC)

call this%clear_accumulator(_RC)
_UNUSED_DUMMY(clock)
_RETURN(_SUCCESS)
_UNUSED_DUMMY(clock)

end subroutine initialize

Expand Down
6 changes: 3 additions & 3 deletions generic3g/actions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ target_sources(MAPL.generic3g PRIVATE

TimeInterpolateAction.F90
AccumulatorAction.F90
MeanAccumulator.F90
MaxAccumulator.F90
MinAccumulator.F90
MeanAction.F90
MaxAction.F90
MinAction.F90
)
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
#include "MAPL_Generic.h"
module mapl3g_MaxAccumulator
module mapl3g_MaxAction
use mapl3g_AccumulatorAction
use MAPL_ExceptionHandling
use MAPL_InternalConstantsMod, only: MAPL_UNDEFINED_REAL, MAPL_UNDEFINED_REAL64
use MAPL_FieldPointerUtilities, only: assign_fptr
use ESMF
implicit none
private
public :: AccumulatorAction
public :: MaxAction

type, extends(AccumulatorAction) :: MaxAccumulator
private
type, extends(AccumulatorAction) :: MaxAction
contains
procedure :: accumulate_R4 => max_accumulate_R4
end type MaxAccumulator
end type MaxAction

interface MaxAccumulator
module procedure :: construct_MaxAccumulator
end interface MaxAccumulator
interface MaxAction
module procedure :: construct_MaxAction
end interface MaxAction

contains

function construct_MaxAccumulator() result(acc)
type(MaxAccumulator) :: acc
function construct_MaxAction() result(acc)
type(MaxAction) :: acc

acc%CLEAR_VALUE_R4 = MAPL_UNDEFINED_REAL

end function construct_MaxAccumulator
end function construct_MaxAction

subroutine max_accumulate_R4(this, update_field, rc)
class(MaxAccumulator), intent(inout) :: this
class(MaxAction), intent(inout) :: this
type(ESMF_Field), intent(inout) :: update_field
integer, optional, intent(out) :: rc

Expand All @@ -49,4 +48,4 @@ subroutine max_accumulate_R4(this, update_field, rc)

end subroutine max_accumulate_R4

end module mapl3g_MaxAccumulator
end module mapl3g_MaxAction
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "MAPL_Generic.h"
module mapl3g_MeanAccumulator
module mapl3g_MeanAction
use mapl3g_AccumulatorAction
use MAPL_InternalConstantsMod, only: MAPL_UNDEFINED_REAL, MAPL_UNDEFINED_REAL64
use MAPL_ExceptionHandling
use MAPL_FieldPointerUtilities
use ESMF
implicit none
private
public :: MeanAccumulator
public :: MeanAction

type, extends(AccumulatorAction) :: MeanAccumulator
type, extends(AccumulatorAction) :: MeanAction
!private
integer(ESMF_KIND_R8) :: counter_scalar = 0_ESMF_KIND_I8
logical, allocatable :: valid_mean(:)
Expand All @@ -21,12 +21,12 @@ module mapl3g_MeanAccumulator
procedure :: calculate_mean_R4
procedure :: clear_valid_mean
procedure :: accumulate_R4 => accumulate_mean_R4
end type MeanAccumulator
end type MeanAction

contains

subroutine clear_mean_accumulator(this, rc)
class(MeanAccumulator), intent(inout) :: this
class(MeanAction), intent(inout) :: this
integer, optional, intent(out) :: rc

integer :: status
Expand All @@ -39,7 +39,7 @@ subroutine clear_mean_accumulator(this, rc)
end subroutine clear_mean_accumulator

subroutine clear_valid_mean(this, rc)
class(MeanAccumulator), intent(inout) :: this
class(MeanAction), intent(inout) :: this
integer, optional, intent(out) :: rc

integer :: status
Expand All @@ -53,7 +53,7 @@ subroutine clear_valid_mean(this, rc)
end subroutine clear_valid_mean

subroutine calculate_mean(this, rc)
class(MeanAccumulator), intent(inout) :: this
class(MeanAction), intent(inout) :: this
integer, optional, intent(out) :: rc

integer :: status
Expand All @@ -71,7 +71,7 @@ subroutine calculate_mean(this, rc)
end subroutine calculate_mean

subroutine update_mean_accumulator(this, importState, exportState, clock, rc)
class(MeanAccumulator), intent(inout) :: this
class(MeanAction), intent(inout) :: this
type(ESMF_State) :: importState
type(ESMF_State) :: exportState
type(ESMF_Clock) :: clock
Expand All @@ -89,7 +89,7 @@ subroutine update_mean_accumulator(this, importState, exportState, clock, rc)
end subroutine update_mean_accumulator

subroutine invalidate_mean_accumulator(this, importState, exportState, clock, rc)
class(MeanAccumulator), intent(inout) :: this
class(MeanAction), intent(inout) :: this
type(ESMF_State) :: importState
type(ESMF_State) :: exportState
type(ESMF_Clock) :: clock
Expand All @@ -104,7 +104,7 @@ subroutine invalidate_mean_accumulator(this, importState, exportState, clock, rc
end subroutine invalidate_mean_accumulator

subroutine calculate_mean_R4(this, rc)
class(MeanAccumulator), intent(inout) :: this
class(MeanAction), intent(inout) :: this
integer, optional, intent(out) :: rc

integer :: status
Expand All @@ -122,7 +122,7 @@ subroutine calculate_mean_R4(this, rc)
end subroutine calculate_mean_R4

subroutine accumulate_mean_R4(this, update_field, rc)
class(MeanAccumulator), intent(inout) :: this
class(MeanAction), intent(inout) :: this
type(ESMF_Field), intent(inout) :: update_field
integer, optional, intent(out) :: rc

Expand All @@ -144,4 +144,4 @@ subroutine accumulate_mean_R4(this, update_field, rc)

end subroutine accumulate_mean_R4

end module mapl3g_MeanAccumulator
end module mapl3g_MeanAction
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
#include "MAPL_Generic.h"
module mapl3g_MinAccumulator
module mapl3g_MinAction
use mapl3g_AccumulatorAction
use MAPL_ExceptionHandling
use MAPL_InternalConstantsMod, only: MAPL_UNDEFINED_REAL, MAPL_UNDEFINED_REAL64
use MAPL_FieldPointerUtilities, only: assign_fptr
use ESMF
implicit none
private
public :: AccumulatorAction
public :: MinAction

type, extends(AccumulatorAction) :: MinAccumulator
private
type, extends(AccumulatorAction) :: MinAction
contains
procedure :: accumulate_R4 => min_accumulate_R4
end type MinAccumulator
end type MinAction

interface MinAccumulator
module procedure :: construct_MinAccumulator
end interface MinAccumulator
interface MinAction
module procedure :: construct_MinAction
end interface MinAction

contains

function construct_MinAccumulator() result(acc)
type(MinAccumulator) :: acc
function construct_MinAction() result(acc)
type(MinAction) :: acc

acc%CLEAR_VALUE_R4 = MAPL_UNDEFINED_REAL

end function construct_MinAccumulator
end function construct_MinAction

subroutine min_accumulate_R4(this, update_field, rc)
class(MinAccumulator), intent(inout) :: this
class(MinAction), intent(inout) :: this
type(ESMF_Field), intent(inout) :: update_field
integer, optional, intent(out) :: rc

Expand All @@ -49,4 +48,4 @@ subroutine min_accumulate_R4(this, update_field, rc)

end subroutine min_accumulate_R4

end module mapl3g_MinAccumulator
end module mapl3g_MinAction
5 changes: 4 additions & 1 deletion generic3g/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ set (test_srcs

Test_CSR_SparseMatrix.pf
Test_AccumulatorAction.pf
Test_MeanAction.pf
Test_MaxAction.pf
Test_MinAction.pf
)


Expand All @@ -45,7 +48,7 @@ add_pfunit_ctest(MAPL.generic3g.tests
LINK_LIBRARIES MAPL.generic3g MAPL.shared MAPL.pfunit scratchpad
EXTRA_INITIALIZE Initialize
EXTRA_USE MAPL_pFUnit_Initialize
OTHER_SOURCES MockUserGridComp.F90 MockItemSpec.F90
OTHER_SOURCES MockUserGridComp.F90 MockItemSpec.F90 accumulator_action_test_common.F90
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
MAX_PES 4
)
Expand Down
Loading

0 comments on commit 372d637

Please sign in to comment.