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

Select short name of variable defining ModelVerticalGrid #3182

Merged
merged 13 commits into from
Nov 20, 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
16 changes: 11 additions & 5 deletions generic3g/ComponentSpecParser/parse_geometry_spec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module function parse_geometry_spec(mapl_cfg, registry, rc) result(geometry_spec
type(GeomManager), pointer :: geom_mgr
class(GeomSpec), allocatable :: geom_spec
integer :: num_levels
character(:), allocatable :: vertical_grid_class, standard_name, units, short_name
character(:), allocatable :: vertical_grid_class, standard_name, units
class(VerticalGrid), allocatable :: vertical_grid
real, allocatable :: levels(:)

Expand Down Expand Up @@ -107,14 +107,20 @@ module function parse_geometry_spec(mapl_cfg, registry, rc) result(geometry_spec
levels = ESMF_HConfigAsR4Seq(vertical_grid_cfg, keyString='levels' ,_RC)
vertical_grid = FixedLevelsVerticalGrid(standard_name, levels, units)
case('model')
num_levels = ESMF_HConfigAsI4(vertical_grid_cfg, keyString='num_levels', _RC)
standard_name = ESMF_HConfigAsString(vertical_grid_cfg, keyString='standard_name', _RC)
units = ESMF_HConfigAsString(vertical_grid_cfg, keyString='units', _RC)
vertical_grid = ModelVerticalGrid(num_levels=num_levels, units=units)
short_name = ESMF_HConfigAsString(vertical_grid_cfg, keyString='short_name', _RC)
num_levels = ESMF_HConfigAsI4(vertical_grid_cfg, keyString='num_levels', _RC)
vertical_grid = ModelVerticalGrid(standard_name=standard_name, units=units, num_levels=num_levels)
select type(vertical_grid)
type is(ModelVerticalGrid)
call vertical_grid%add_variant(short_name=short_name)
call vertical_grid%set_registry(registry)
if (standard_name == "air_pressure") then
call vertical_grid%add_short_name(edge="PLE", center="PL")
else if (standard_name == "height") then
call vertical_grid%add_short_name(edge="ZLE", center="ZL")
else
_FAIL("unsupported standard name ["//standard_name//"]")
end if
end select
case default
_FAIL('vertical grid class '//vertical_grid_class//' not supported')
Expand Down
18 changes: 3 additions & 15 deletions generic3g/tests/Test_ModelVerticalGrid.pf
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ contains
rc = 0
! Inside user "set_geom" phase.
geom = make_geom(_RC)
vgrid = ModelVerticalGrid(num_levels=LM, units="hPa")
call vgrid%add_variant(short_name=var_name)
vgrid = ModelVerticalGrid(standard_name="air_pressure", units="hPa", num_levels=LM)
call vgrid%add_short_name(edge="PLE", center="PL")

! inside OuterMeta
r = StateRegistry("dyn")
Expand Down Expand Up @@ -114,22 +114,10 @@ contains
integer :: num_levels

num_levels = 10
vgrid = ModelVerticalGrid(num_levels=num_levels, units="hPa")
vgrid = ModelVerticalGrid(standard_name="height", units="m", num_levels=num_levels)
@assert_that(vgrid%get_num_levels(), is(num_levels))
end subroutine test_num_levels

@test
subroutine test_num_variants()
type(ModelVerticalGrid) :: vgrid

vgrid = ModelVerticalGrid(num_levels=3, units="hPa")
@assert_that(vgrid%get_num_variants(), is(0))
call vgrid%add_variant(short_name="PLE")
@assert_that(vgrid%get_num_variants(), is(1))
call vgrid%add_variant(short_name="ZLE")
@assert_that(vgrid%get_num_variants(), is(2))
end subroutine test_num_variants

@test(type=ESMF_TestMethod, npes=[1])
subroutine test_created_fields_have_num_levels(this)
class(ESMF_TestMethod), intent(inout) :: this
Expand Down
4 changes: 2 additions & 2 deletions generic3g/tests/scenarios/vertical_regridding_2/A.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ mapl:
dateline: DC
vertical_grid:
class: model
short_name: PLE
standard_name: air_pressure
units: hPa
num_levels: 4

states:
import: {}
export:
PLE:
PL:
standard_name: air_pressure
units: hPa
default_value: 17.
Expand Down
4 changes: 2 additions & 2 deletions generic3g/tests/scenarios/vertical_regridding_2/C.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ mapl:
dateline: DC
vertical_grid:
class: model
short_name: ZLE
standard_name: height
units: m
num_levels: 4

states:
import: {}
export:
ZLE:
ZL:
standard_name: height
units: m
default_value: 23.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

- component: A
export:
PLE: {status: complete}
PL: {status: complete}

- component: B
import:
I_B: {status: complete}

- component: C
export:
ZLE: {status: complete}
ZL: {status: complete}

- component: D
import:
Expand Down
4 changes: 2 additions & 2 deletions generic3g/tests/scenarios/vertical_regridding_2/parent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ mapl:
states: {}

connections:
- src_name: PLE
- src_name: PL
dst_name: I_B
src_comp: A
dst_comp: B
- src_name: ZLE
- src_name: ZL
dst_name: I_D
src_comp: C
dst_comp: D
2 changes: 1 addition & 1 deletion generic3g/tests/scenarios/vertical_regridding_3/DYN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mapl:
dateline: DC
vertical_grid:
class: model
short_name: PL
standard_name: air_pressure
units: hPa
num_levels: 4

Expand Down
74 changes: 7 additions & 67 deletions generic3g/vertical/FixedLevelsVerticalGrid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module mapl3g_FixedLevelsVerticalGrid
use mapl3g_FieldCreate
use mapl3g_GriddedComponentDriver
use mapl3g_VerticalDimSpec
use mapl3g_FieldCondensedArray, only: assign_fptr_condensed_array
use esmf

implicit none
Expand Down Expand Up @@ -71,23 +72,19 @@ subroutine get_coordinate_field(this, field, coupler, standard_name, geom, typek
integer, optional, intent(out) :: rc

real(kind=ESMF_KIND_R4), pointer :: farray3d(:, :, :)
integer, allocatable :: local_cell_count(:)
integer :: i, j, IM, JM, status
integer :: shape_(3), horz, ungrd, status

! _HERE
! print *, "units: ", units
field = MAPL_FieldCreate( &
geom=geom, &
typekind=ESMF_TYPEKIND_R4, &
num_levels=size(this%levels), &
vert_staggerloc=VERTICAL_STAGGER_CENTER, &
_RC)
! Copy the 1D array, levels(:), to each point on the horz grid
call ESMF_FieldGet(field, fArrayPtr=farray3d, _RC)
call MAPL_GeomGet_(geom, localCellCount=local_cell_count, _RC)
IM = local_cell_count(1); JM = local_cell_count(2)
do concurrent (i=1:IM, j=1:JM)
farray3d(i, j, :) = this%levels(:)
! Copy the 1D array, levels(:), to each point of the horz grid
call assign_fptr_condensed_array(field, farray3d, _RC)
shape_ = shape(farray3d)
do concurrent (horz=1:shape_(1), ungrd=1:shape_(3))
farray3d(horz, :, ungrd) = this%levels(:)
end do

_RETURN(_SUCCESS)
Expand Down Expand Up @@ -146,61 +143,4 @@ impure elemental logical function not_equal_FixedLevelsVerticalGrid(a, b) result
not_equal = .not. (a==b)
end function not_equal_FixedLevelsVerticalGrid

! Create an ESMF_Field containing a 3D array that is replicated from
! a 1D array at each point of the horizontal grid
function esmf_field_create_(geom, farray1d, rc) result(field)
type(ESMF_Field) :: field ! result
type(ESMF_Geom), intent(in) :: geom
real(kind=ESMF_KIND_R4), intent(in) :: farray1d(:)
!# character(len=*), intent(in) :: vloc
integer, optional, intent(out) :: rc

integer, allocatable :: local_cell_count(:)
real(kind=ESMF_KIND_R4), pointer :: farray3d(:, :, :)
integer :: i, j, IM, JM, status

!# ! First, copy the 1D array, farray1d, to each point on the horz grid
!# allocate(farray3d(IM, JM, size(farray1d)))
!# do concurrent (i=1:IM, j=1:JM)
!# farray3d(i, j, :) = farray1d(:)
!# end do

! Create an ESMF_Field containing farray3d
field = MAPL_FieldCreate( &
geom=geom, typekind=ESMF_TYPEKIND_R4, &
num_levels=size(farray1d), &
vert_staggerloc=VERTICAL_STAGGER_CENTER, &
_RC)

!# ! First, copy the 1D array, farray1d, to each point on the horz grid
call ESMF_FieldGet(field, fArrayPtr=farray3d, _RC)
call MAPL_GeomGet_(geom, localCellCount=local_cell_count, _RC)
IM = local_cell_count(1); JM = local_cell_count(2)
do concurrent (i=1:IM, j=1:JM)
farray3d(i, j, :) = farray1d(:)
end do


_RETURN(_SUCCESS)
end function esmf_field_create_

! Temporary version here while the detailed MAPL_GeomGet utility gets developed
subroutine MAPL_GeomGet_(geom, localCellCount, rc)
use MAPLBase_Mod
type(ESMF_Geom), intent(in) :: geom
integer, allocatable, intent(out), optional :: localCellCount(:)
integer, intent(out), optional :: rc

type(ESMF_Grid) :: grid
integer :: status

if (present(localCellCount)) then
call ESMF_GeomGet(geom, grid=grid)
allocate(localCellCount(3), source=-1)
call MAPL_GridGet(grid, localCellCountPerDim=localCellCount, _RC)
end if

_RETURN(_SUCCESS)
end subroutine MAPL_GeomGet_

end module mapl3g_FixedLevelsVerticalGrid
Loading