Skip to content

Commit

Permalink
Merge pull request #3231 from GEOS-ESM/feature/pchakrab/update-config…
Browse files Browse the repository at this point in the history
…urable-gridcomp

Replace Simple Leaf/Parent grid comps withe configurable gridcomp
  • Loading branch information
tclune authored Dec 10, 2024
2 parents 02e7a91 + 93bf4e2 commit 428fb37
Show file tree
Hide file tree
Showing 49 changed files with 203 additions and 998 deletions.
3 changes: 2 additions & 1 deletion generic3g/specs/FieldSpec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,8 @@ subroutine adapt_vertical_grid(this, spec, action, rc)
v_out_coord, v_out_coupler, & ! output
'ignore', this%geom, this%typekind, this%units, this%vertical_dim_spec, _RC)
action = VerticalRegridAction(v_in_coord, v_out_coupler, v_out_coord, v_out_coupler, this%regrid_method)
spec%vertical_grid = this%vertical_grid
if (allocated(spec%vertical_grid)) deallocate(spec%vertical_grid)
allocate(spec%vertical_grid, source=this%vertical_grid)
spec%vertical_dim_spec = this%vertical_dim_spec
end select

Expand Down
38 changes: 17 additions & 21 deletions generic3g/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
set(MODULE_DIRECTORY "${esma_include}/MAPL.generic3g/tests")

add_library(scratchpad SHARED scratchpad.F90)

add_subdirectory(gridcomps)

set (test_srcs

Test_VirtualConnectionPt.pf

Test_SimpleLeafGridComp.pf
Test_SimpleParentGridComp.pf
Test_RunChild.pf
Test_ConfigurableGridComp.pf

Test_AddFieldSpec.pf
Test_ComponentSpecParser.pf
Expand Down Expand Up @@ -40,18 +35,18 @@ set (test_srcs
Test_MeanAction.pf
Test_MaxAction.pf
Test_MinAction.pf
)


add_pfunit_ctest(MAPL.generic3g.tests
TEST_SOURCES ${test_srcs}
LINK_LIBRARIES MAPL.generic3g MAPL.shared MAPL.pfunit scratchpad
EXTRA_INITIALIZE Initialize
EXTRA_USE MAPL_pFUnit_Initialize
OTHER_SOURCES MockUserGridComp.F90 MockItemSpec.F90 accumulator_action_test_common.F90
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
MAX_PES 4
)
)

add_pfunit_ctest(
MAPL.generic3g.tests
TEST_SOURCES ${test_srcs}
LINK_LIBRARIES MAPL.generic3g MAPL.shared MAPL.pfunit configurable_gridcomp
EXTRA_INITIALIZE Initialize
EXTRA_USE MAPL_pFUnit_Initialize
OTHER_SOURCES MockUserGridComp.F90 MockItemSpec.F90 accumulator_action_test_common.F90
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
MAX_PES 4
)
set_target_properties(MAPL.generic3g.tests PROPERTIES Fortran_MODULE_DIRECTORY ${MODULE_DIRECTORY})
set_tests_properties(MAPL.generic3g.tests PROPERTIES LABELS "ESSENTIAL")

Expand All @@ -64,9 +59,10 @@ endif ()
# This test also requires UDUNITS2_XML_PATH to be set to the location of the udunits2.xml file
# This is found by Findudunits.cmake and stored in the variable udunits_XML_PATH

set_tests_properties(MAPL.generic3g.tests
PROPERTIES ENVIRONMENT "${LD_PATH}=${CMAKE_CURRENT_BINARY_DIR}/gridcomps:$ENV{${LD_PATH}};UDUNITS2_XML_PATH=${udunits_XML_PATH}"
)
set_tests_properties(
MAPL.generic3g.tests
PROPERTIES ENVIRONMENT "${LD_PATH}=${CMAKE_CURRENT_BINARY_DIR}/gridcomps:${CMAKE_BINARY_DIR}/lib:$ENV{${LD_PATH}};UDUNITS2_XML_PATH=${udunits_XML_PATH}"
)

add_dependencies(build-tests MAPL.generic3g.tests)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "MAPL_TestErr.h"
module Test_SimpleParentGridComp

module Test_ConfigurableGridComp

use mapl3g_GenericPhases
use mapl3g_Generic
use mapl3g_UserSetServices
Expand All @@ -25,7 +27,7 @@ contains
type(ESMF_GridComp), intent(inout) :: outer_gc
type(MultiState), intent(out) :: states
integer, intent(out) :: rc

integer :: status, userRC
type(ESMF_Grid) :: grid
type(ESMF_HConfig) :: config
Expand All @@ -44,7 +46,7 @@ contains
call ESMF_TimeIntervalSet(dt, h=1)
clock = ESMF_ClockCreate(dt, t)

outer_gc = create_grid_comp('P', user_setservices('libsimple_parent_gridcomp'), config, clock, _RC)
outer_gc = create_grid_comp('P', user_setservices('libconfigurable_gridcomp'), config, clock, _RC)
call ESMF_GridCompSetServices(outer_gc, setServices, userRC=userRC, _RC)
_VERIFY(userRC)
grid = ESMF_GridCreateNoPeriDim(maxIndex=[4,4], name='I_AM_GROOT', _RC)
Expand All @@ -55,7 +57,6 @@ contains
associate (import => states%importState, export => states%exportState)
import = ESMF_StateCreate(_RC)
export = ESMF_StateCreate(_RC)

do i = 1, size(GENERIC_INIT_PHASE_SEQUENCE)
associate (phase => GENERIC_INIT_PHASE_SEQUENCE(i))
call ESMF_GridCompInitialize(outer_gc, &
Expand All @@ -64,21 +65,18 @@ contains
_VERIFY(userRC)
end associate
end do

end associate

rc = 0

end subroutine setup


subroutine tearDown(outer_gc)
type(ESMF_GridComp), intent(inout) :: outer_gc
end subroutine tearDown


@test(npes=[0])
subroutine test_child_user_items_created(this)

class(MpiTestMethod), intent(inout) :: this

integer :: status
Expand Down Expand Up @@ -120,13 +118,13 @@ contains

status = 1

child_comp = outer_meta%get_child(child_name, rc=status)
child_comp = outer_meta%get_child(child_name, rc=status)
if (status /= 0) then
status = 2
return
end if
child_gc = child_comp%get_gridcomp()

child_gc = child_comp%get_gridcomp()
child_meta => get_outer_meta(child_gc)
user_component => child_meta%get_user_gc_driver()
states = user_component%get_states()
Expand All @@ -145,14 +143,13 @@ contains
end do

status = 0

end function check

end subroutine test_child_user_items_created


@test(npes=[0])
subroutine test_child_outer_items_created(this)

class(MpiTestMethod), intent(inout) :: this

integer :: status
Expand All @@ -176,8 +173,8 @@ contains
call get_field(f, states, state_intent='export', field_name='E_A1', rc=status)
@assert_that(status, is(0))
call get_field(f, states, state_intent='internal', field_name='Z_A1', rc=status)
@assert_that(status, is(0))
@assert_that(status, is(0))

call get_child_user_states(states, outer_meta, 'child_B', rc=status)
@assert_that(status, is(0))

Expand All @@ -188,11 +185,6 @@ contains
call get_field(f, states, state_intent='internal', field_name='Z_B1', rc=status)
@assert_that(status, is(0))

!!$ @assert_that('import', check('child_B', 'import', ['I_B1']), is(0))
!!$ @assert_that('export', check('child_B', 'export', ['E_B1']), is(0))
!!$ @assert_that('internal', check('child_B', 'internal', ['Z_B1']), is(0))


contains

integer function check(child_name, state_intent, expected_items) result(status)
Expand All @@ -215,7 +207,7 @@ contains
status = 2
return
end if

child_gc = child_comp%get_gridcomp()
child_meta => get_outer_meta(child_gc)
user_component => child_meta%get_user_gc_driver()
Expand All @@ -226,7 +218,7 @@ contains
status = 3
return
end if

do i = 1, size(expected_items)
call ESMF_StateGet(state, trim(expected_items(i)), f, rc=status)
if (status /= 0) then
Expand All @@ -236,13 +228,13 @@ contains
end do

status = 0

end function check

end subroutine test_child_outer_items_created

@test(npes=[0])
subroutine test_parent_user_items_created(this)

class(MpiTestMethod), intent(inout) :: this

integer :: status
Expand Down Expand Up @@ -296,10 +288,12 @@ contains
end if
status = 0
end function check

end subroutine test_parent_user_items_created

@test(npes=[0])
subroutine test_parent_outer_items_created(this)

class(MpiTestMethod), intent(inout) :: this

integer :: status
Expand All @@ -317,7 +311,6 @@ contains
@assert_that(check(states, 'export', field_name='child_B/E_B1'), is(0))
@assert_that(check(states, 'export', field_name='child_B/Z_B1'), is(5))


contains

integer function check(states, state_intent, field_name) result(status)
Expand Down Expand Up @@ -369,7 +362,6 @@ contains
end if

status = 0

end function check

end subroutine test_parent_outer_items_created
Expand All @@ -393,14 +385,13 @@ contains
rc = +2
return
end if

child_gc = child_comp%get_gridcomp()
child_meta => get_outer_meta(child_gc, rc=status)
user_component => child_meta%get_user_gc_driver()
states = user_component%get_states()

rc = 0

end subroutine get_child_user_states

subroutine get_field(field, states, state_intent, unusable, field_name, substate_name, rc)
Expand Down Expand Up @@ -439,11 +430,11 @@ contains
end if

rc = 0

end subroutine get_field

@test(npes=[0])
subroutine test_state_items_complete(this)

class(MpiTestMethod), intent(inout) :: this

integer :: status
Expand All @@ -470,6 +461,7 @@ contains
@assert_that(status, is(0))

if(.false.) print*,shape(this)

contains

subroutine check(child_name, state_intent, item, expected_status, rc)
Expand All @@ -492,7 +484,7 @@ contains

call states%get_state(state, state_intent, rc=status)
@assert_that(status, is(0))

call ESMF_StateGet(state, item, f, rc=status)
@assert_that('Item <'//item//'> not found in child <'//child_name//'>.', status, is(0))

Expand All @@ -503,9 +495,8 @@ contains

rc = 0
end subroutine check

end subroutine test_state_items_complete

end subroutine test_state_items_complete

@test(npes=[0])
subroutine test_propagate_imports(this)
Expand All @@ -524,7 +515,6 @@ contains
! Child A import is unsatisfied, so it should propagate up
call ESMF_StateGet(states%importState, 'I_A1(1)', f, rc=status)
@assert_that('Expected unsatisfied import in parent.', status, is(0))

end subroutine test_propagate_imports

end module Test_SimpleParentGridComp
end module Test_ConfigurableGridComp
Loading

0 comments on commit 428fb37

Please sign in to comment.