Skip to content

Commit

Permalink
Merge pull request #2584 from GEOS-ESM/bugfix/wdboggs/#2549A-fix_fiel…
Browse files Browse the repository at this point in the history
…d_utils

Fix field utils tests
  • Loading branch information
tclune authored Feb 8, 2024
2 parents 2233416 + cefa47c commit 5c8180c
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 188 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
we anticipate this here
- Add explicit `Fortran_MODULE_DIRECTORY` to `CMakeLists.txt` in benchmarks to avoid race condition in Ninja builds
- Add check to make sure ESMF was not built as `mpiuni`
- Fixed failing tests for `field_utils`.

### Removed

Expand Down
63 changes: 34 additions & 29 deletions field_utils/tests/Test_FieldArithmetic.pf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Test_FieldArithmetic
use MAPL_FieldUtilities
use MAPL_FieldPointerUtilities
use ESMF
use funit
use pfunit
use MAPL_ExceptionHandling

implicit none
Expand All @@ -21,8 +21,8 @@ contains
! Making the fields should be done in the tests themselves so because
! of the npes argument.
@Before
subroutine set_up_data()
implicit none
subroutine set_up_data(this)
class(MpiTestMethod), intent(inout) :: this

integer :: status, rc

Expand All @@ -35,23 +35,25 @@ contains
allocate(y8array, source=R8_ARRAY_DEFAULT)
y4array = y4array + ADD_R4
y8array = y8array + ADD_R8
XR4 = mk_field(R4_ARRAY_DEFAULT, regDecomp=REG_DECOMP_DEFAULT, minIndex=MIN_INDEX_DEFAULT, maxIndex=MAX_INDEX_DEFAULT, &
indexflag=INDEX_FLAG_DEFAULT, name = 'XR4', _RC)
YR4 = mk_field(y4array, regDecomp=REG_DECOMP_DEFAULT, minIndex=MIN_INDEX_DEFAULT, maxIndex=MAX_INDEX_DEFAULT, &
indexflag=INDEX_FLAG_DEFAULT, name = 'YR4', _RC)
XR8 = mk_field(R8_ARRAY_DEFAULT, regDecomp=REG_DECOMP_DEFAULT, minIndex=MIN_INDEX_DEFAULT, maxIndex=MAX_INDEX_DEFAULT, &
indexflag=INDEX_FLAG_DEFAULT, name = 'XR8', _RC)
YR8 = mk_field(y8array, regDecomp=REG_DECOMP_DEFAULT, minIndex=MIN_INDEX_DEFAULT, maxIndex=MAX_INDEX_DEFAULT, &
indexflag=INDEX_FLAG_DEFAULT, name = 'YR8', _RC)
XR4 = mk_field(R4_ARRAY_DEFAULT, name = 'XR4', _RC)
YR4 = mk_field(y4array, name = 'YR4', _RC)
XR8 = mk_field(R8_ARRAY_DEFAULT, name = 'XR8', _RC)
YR8 = mk_field(y8array, name = 'YR8', _RC)
call ESMF_AttributeSet(xr4,name="missing_value",value=undef,_RC)
call ESMF_AttributeSet(xr8,name="missing_value",value=undef,_RC)
call ESMF_AttributeSet(yr4,name="missing_value",value=undef,_RC)
call ESMF_AttributeSet(yr8,name="missing_value",value=undef,_RC)

end subroutine set_up_data

@Test(npes=product(REG_DECOMP_DEFAULT))
subroutine test_FieldAddR4()
@after
subroutine teardown(this)
class(MpiTestMethod), intent(inout) :: this
end subroutine teardown

@Test(npes=[4])
subroutine test_FieldAddR4(this)
class(MpiTestMethod), intent(inout) :: this
type(ESMF_Field) :: x
type(ESMF_Field) :: y
real(kind=ESMF_KIND_R4), pointer :: x_ptr(:,:), y_ptr(:,:)
Expand All @@ -66,19 +68,17 @@ contains
call ESMF_FieldGet(y , farrayPtr = y_ptr, _RC)

x_ptr = 2.0
y_ptr = 3.0
y_ptr = 3.0
result_array = x_ptr
result_array = 5.0
call FieldAdd(y, x, y, _RC)
@assertEqual(y_ptr, result_array)

end subroutine test_FieldAddR4

! Rather than use the fields created in setup, make the fields
! in this subroutine to make sure that the npes match the
! regDecomp.
@Test(npes=product(REG_DECOMP_DEFAULT))
subroutine test_FieldAddR4_missing
@Test(npes=[4])
subroutine test_FieldAddR4_missing(this)
class(MpiTestMethod), intent(inout) :: this
type(ESMF_Field) :: x
type(ESMF_Field) :: y
real(kind=ESMF_KIND_R4), pointer :: x_ptr(:,:), y_ptr(:,:)
Expand All @@ -98,8 +98,9 @@ contains
@assertEqual(y_ptr, result_array)
end subroutine test_FieldAddR4_missing

@Test(npes=product(REG_DECOMP_DEFAULT))
subroutine test_FieldAddR8()
@Test(npes=[4])
subroutine test_FieldAddR8(this)
class(MpiTestMethod), intent(inout) :: this
type(ESMF_Field) :: x
type(ESMF_Field) :: y
real(kind=ESMF_KIND_R8), pointer :: x_ptr(:,:), y_ptr(:,:)
Expand All @@ -121,8 +122,9 @@ contains
@assertEqual(y_ptr, result_array)
end subroutine test_FieldAddR8

@Test(npes=product(REG_DECOMP_DEFAULT))
subroutine test_FieldPowR4()
@Test(npes=[4])
subroutine test_FieldPowR4(this)
class(MpiTestMethod), intent(inout) :: this
type(ESMF_Field) :: x
real(kind=ESMF_KIND_R4), pointer :: x_ptr(:,:)
real(kind=ESMF_KIND_R4), allocatable :: result_array(:,:)
Expand All @@ -140,8 +142,9 @@ contains
@assertEqual(x_ptr, result_array)
end subroutine test_FieldPowR4

@Test(npes=product(REG_DECOMP_DEFAULT))
subroutine test_FieldPowR8()
@Test(npes=[4])
subroutine test_FieldPowR8(this)
class(MpiTestMethod), intent(inout) :: this
type(ESMF_Field) :: x
real(kind=ESMF_KIND_R8), pointer :: x_ptr(:,:)
real(kind=ESMF_KIND_R8), allocatable :: result_array(:,:)
Expand All @@ -159,8 +162,9 @@ contains
@assertEqual(x_ptr, result_array)
end subroutine test_FieldPowR8

@Test(npes=product(REG_DECOMP_DEFAULT))
subroutine test_FieldSinR4()
@Test(npes=[4])
subroutine test_FieldSinR4(this)
class(MpiTestMethod), intent(inout) :: this
type(ESMF_Field) :: x
real(kind=ESMF_KIND_R4), pointer :: x_ptr(:,:)
real(kind=ESMF_KIND_R4), allocatable :: result_array(:,:)
Expand All @@ -176,8 +180,9 @@ contains
@assertEqual(x_ptr, result_array)
end subroutine test_FieldSinR4

@Test(npes=product(REG_DECOMP_DEFAULT))
subroutine test_FieldNegR4()
@Test(npes=[4])
subroutine test_FieldNegR4(this)
class(MpiTestMethod), intent(inout) :: this
type(ESMF_Field) :: x
real(kind=ESMF_KIND_R4), pointer :: x_ptr(:,:)
real(kind=ESMF_KIND_R4), allocatable :: result_array(:,:)
Expand Down
Loading

0 comments on commit 5c8180c

Please sign in to comment.