Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability, in Scenarios tests, to allow for testing array slices in the k direction #3192

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 104 additions & 10 deletions generic3g/tests/Test_Scenarios.pf
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ module Test_Scenarios

interface Scenario
procedure :: new_Scenario
end interface
end interface Scenario

interface ScenarioDescription
procedure :: new_ScenarioDescription
end interface
end interface ScenarioDescription

contains

Expand Down Expand Up @@ -100,6 +100,7 @@ contains
params = [params, add_params('field status', check_field_status)]
params = [params, add_params('field typekind', check_field_typekind)]
params = [params, add_params('field value', check_field_value)]
params = [params, add_params('field k_values', check_field_k_values)]
params = [params, add_params('field exists', check_field_rank)]

! Service oriented tests
Expand Down Expand Up @@ -453,7 +454,6 @@ contains
character(*), intent(in) :: description
integer, intent(out) :: rc

character(len=:), allocatable :: expected_field_typekind_str
real :: expected_field_value
integer :: rank
type(ESMF_TypeKind_Flag) :: typekind
Expand All @@ -470,7 +470,7 @@ contains
return
end if

if (.not. ESMF_HConfigIsDefined(expectations,keyString='value')) then
if (.not. ESMF_HConfigIsDefined(expectations,keyString='value')) then
rc = 0
return
end if
Expand All @@ -486,13 +486,13 @@ contains
real(kind=ESMF_KIND_R4), pointer :: x2(:,:),x3(:,:,:),x4(:,:,:,:)
select case(rank)
case(2)
call ESMF_FieldGet(field, farrayptr=x2, _RC)
call ESMF_FieldGet(field, farrayPtr=x2, _RC)
@assert_that('value of '//short_name, all(x2 == expected_field_value), is(true()))
case(3)
call ESMF_FieldGet(field, farrayptr=x3, _RC)
call ESMF_FieldGet(field, farrayPtr=x3, _RC)
@assert_that('value of '//short_name, all(x3 == expected_field_value), is(true()))
case(4)
call ESMF_FieldGet(field, farrayptr=x4, _RC)
call ESMF_FieldGet(field, farrayPtr=x4, _RC)
@assert_that('value of '//short_name, all(x4 == expected_field_value), is(true()))
end select
end block
Expand All @@ -501,13 +501,13 @@ contains
real(kind=ESMF_KIND_R8), pointer :: x2(:,:),x3(:,:,:),x4(:,:,:,:)
select case(rank)
case(2)
call ESMF_FieldGet(field, farrayptr=x2, _RC)
call ESMF_FieldGet(field, farrayPtr=x2, _RC)
@assert_that('value of '//short_name, all(x2 == expected_field_value), is(true()))
case(3)
call ESMF_FieldGet(field, farrayptr=x3, _RC)
call ESMF_FieldGet(field, farrayPtr=x3, _RC)
@assert_that('value of '//short_name, all(x3 == expected_field_value), is(true()))
case(4)
call ESMF_FieldGet(field, farrayptr=x4, _RC)
call ESMF_FieldGet(field, farrayPtr=x4, _RC)
@assert_that('value of '//short_name, all(x4 == expected_field_value), is(true()))
end select
end block
Expand All @@ -518,6 +518,100 @@ contains
rc = 0
end subroutine check_field_value

subroutine check_field_k_values(expectations, state, short_name, description, rc)
type(ESMF_HConfig), intent(in) :: expectations
type(ESMF_State), intent(inout) :: state
character(*), intent(in) :: short_name
character(*), intent(in) :: description
integer, intent(out) :: rc

real, allocatable :: expected_k_values(:)
integer :: rank
type(ESMF_TypeKind_Flag) :: typekind
integer :: status
character(len=:), allocatable :: msg
type(ESMF_Field) :: field
type(ESMF_StateItem_Flag) :: itemtype
integer :: i, j, l, shape3(3), shape4(4)

msg = description

itemtype = get_itemtype(state, short_name, _RC)
if (itemtype /= ESMF_STATEITEM_FIELD) then ! that's ok
rc = 0
return
end if

if (.not. ESMF_HConfigIsDefined(expectations,keyString='k_values')) then
rc = 0
return
end if

expected_k_values = ESMF_HConfigAsR4Seq(expectations,keyString='k_values',_RC)

call ESMF_StateGet(state, short_name, field, _RC)
call ESMF_FieldGet(field, typekind=typekind, rank=rank, rc=status)
@assert_that('field get failed '//short_name, status, is(0))

if (typekind == ESMF_TYPEKIND_R4) then
block
real(kind=ESMF_KIND_R4), pointer :: x3(:, :, :), x4(:, :, :, :)
select case(rank)
case(3)
call ESMF_FieldGet(field, farrayPtr=x3, _RC)
shape3 = shape(x3)
do i = 1, shape3(1)
do j = 1, shape3(2)
@assert_that("value of "//short_name, x3(i, j, :), is(equal_to(expected_k_values)))
end do
end do
case(4)
call ESMF_FieldGet(field, farrayPtr=x4, _RC)
shape4 = shape(x4)
do i = 1, shape4(1)
do j = 1, shape4(2)
do l = 1, shape4(4)
@assert_that("value of "//short_name, x4(i, j, :, l), is(equal_to(expected_k_values)))
end do
end do
end do
case default
error stop "invalid rank"
end select
end block
elseif (typekind == ESMF_TYPEKIND_R8) then
block
real(kind=ESMF_KIND_R8), pointer :: x3(:, :, :), x4(:, :, :, :)
select case(rank)
case(3)
call ESMF_FieldGet(field, farrayPtr=x3, _RC)
shape3 = shape(x3)
do i = 1, shape3(1)
do j = 1, shape3(2)
@assert_that("value of "//short_name, x3(i, j, :), is(equal_to(expected_k_values)))
end do
end do
case(4)
call ESMF_FieldGet(field, farrayPtr=x4, _RC)
shape4 = shape(x4)
do i = 1, shape4(1)
do j = 1, shape4(2)
do l = 1, shape4(4)
@assert_that("value of "//short_name, x4(i, j, :, l), is(equal_to(expected_k_values)))
end do
end do
end do
pchakraborty marked this conversation as resolved.
Show resolved Hide resolved
case default
error stop "invalid rank"
end select
end block
else
_VERIFY(-1)
end if

rc = 0
end subroutine check_field_k_values

subroutine check_field_rank(expectations, state, short_name, description, rc)
type(ESMF_HConfig), intent(in) :: expectations
type(ESMF_State), intent(inout) :: state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
- component: DYN
export:
PL: {status: complete}
T_DYN: {status: complete}
T_DYN: {status: complete, typekind: R4, rank: 3, k_values: [40., 20., 10., 5.]}

- component: PHYS
import:
T_PHYS: {status: complete}
T_PHYS: {status: complete, typekind: R4, rank: 3, k_values: [18., 6.]}

- component: C
import:
I_C: {status: complete}
I_C: {status: complete, typekind: R4, rank: 3, k_values: [40., 20., 10.]}
Loading