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

Marginal progress on vertical grid support. #2979

Merged
merged 3 commits into from
Aug 21, 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
31 changes: 18 additions & 13 deletions generic3g/specs/FieldSpec.F90
Original file line number Diff line number Diff line change
Expand Up @@ -477,18 +477,22 @@ logical function can_connect_to(this, src_spec, rc)
class(StateItemSpec), intent(in) :: src_spec
integer, optional, intent(out) :: rc

logical :: can_convert_units_
logical :: can_convert_units
logical :: can_connect_vertical_grid
integer :: status

select type(src_spec)
class is (FieldSpec)
can_convert_units_ = can_connect_units(this%units, src_spec%units, _RC)
can_convert_units = can_connect_units(this%units, src_spec%units, _RC)
can_connect_vertical_grid = this%vertical_grid%can_connect_to(src_spec%vertical_grid, _RC)

can_connect_to = all ([ &
can_match(this%geom,src_spec%geom), &
can_connect_vertical_grid, &
match(this%vertical_dim_spec,src_spec%vertical_dim_spec), &
match(this%ungridded_dims,src_spec%ungridded_dims), &
includes(this%attributes, src_spec%attributes), &
can_convert_units_ &
can_convert_units &
])
class default
can_connect_to = .false.
Expand Down Expand Up @@ -636,16 +640,16 @@ subroutine make_extension_safely(this, dst_spec, new_spec, action, rc)
_RETURN(_SUCCESS)
end if

_ASSERT(allocated(this%vertical_grid), 'Source spec must specify a valid vertical grid.')
if (.not. same_vertical_grid(this%vertical_grid, dst_spec%vertical_grid)) then
_HERE
call this%vertical_grid%get_coordinate_field(v_in_coord, v_in_coupler, &
'ignore', this%geom, this%typekind, this%units, _RC)
call this%vertical_grid%get_coordinate_field(v_out_coord, v_out_coupler, &
'ignore', dst_spec%geom, dst_spec%typekind, dst_spec%units, _RC)
action = VerticalRegridAction(v_in_coord, v_out_coupler, v_out_coord, v_out_coupler, VERTICAL_REGRID_LINEAR)
_RETURN(_SUCCESS)
end if
_ASSERT(allocated(this%vertical_grid), 'Source spec must specify a valid vertical grid.')
if (.not. same_vertical_grid(this%vertical_grid, dst_spec%vertical_grid)) then
_HERE
call this%vertical_grid%get_coordinate_field(v_in_coord, v_in_coupler, &
'ignore', this%geom, this%typekind, this%units, _RC)
call this%vertical_grid%get_coordinate_field(v_out_coord, v_out_coupler, &
'ignore', dst_spec%geom, dst_spec%typekind, dst_spec%units, _RC)
action = VerticalRegridAction(v_in_coord, v_out_coupler, v_out_coord, v_out_coupler, VERTICAL_REGRID_LINEAR)
_RETURN(_SUCCESS)
end if

!# if (.not. same_freq_spec(this%freq_spec, dst_spec%freq_spec)) then
!# action = VerticalRegridAction(this%freq_spec, dst_spec%freq_spec
Expand Down Expand Up @@ -720,6 +724,7 @@ logical function can_match_geom(a, b) result(can_match)

end function can_match_geom


logical function match_geom(a, b) result(match)
type(ESMF_Geom), allocatable, intent(in) :: a, b

Expand Down
11 changes: 11 additions & 0 deletions generic3g/vertical/BasicVerticalGrid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module mapl3g_BasicVerticalGrid
contains
procedure :: get_num_levels
procedure :: get_coordinate_field
procedure :: can_connect_to
end type BasicVerticalGrid

interface operator(==)
Expand All @@ -31,6 +32,15 @@ module mapl3g_BasicVerticalGrid
module procedure new_BasicVerticalGrid
end interface BasicVerticalGrid

interface
module function can_connect_to(this, src, rc)
logical :: can_connect_to
class(BasicVerticalGrid), intent(in) :: this
class(VerticalGrid), intent(in) :: src
integer, optional, intent(out) :: rc
end function
end interface

contains

function new_BasicVerticalGrid(num_levels) result(vertical_grid)
Expand Down Expand Up @@ -69,4 +79,5 @@ elemental logical function not_equal_to(a, b)
not_equal_to = .not. (a == b)
end function not_equal_to


end module mapl3g_BasicVerticalGrid
27 changes: 27 additions & 0 deletions generic3g/vertical/BasicVerticalGrid/can_connect_to.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "MAPL_ErrLog.h"
submodule (mapl3g_BasicVerticalGrid) can_connect_to_smod
use mapl3g_MirrorVerticalGrid
use mapl3g_ModelVerticalGrid

contains

logical module function can_connect_to(this, src, rc)
class(BasicVerticalGrid), intent(in) :: this
class(VerticalGrid), intent(in) :: src
integer, optional, intent(out) :: rc

select type(src)
type is (BasicVerticalGrid)
can_connect_to = (this%get_num_levels() == src%get_num_levels())
type is (MirrorVerticalGrid)
can_connect_to = .true.
type is (ModelVerticalGrid)
can_connect_to = (this%get_num_levels() == src%get_num_levels())
class default
_FAIL('BasicVerticalGrid can only connect to src BasicVerticalGrid, MirrorVerticalGrid, or ModelVerticalGrid instances.')
end select

_RETURN(_SUCCESS)
end function can_connect_to

end submodule
15 changes: 14 additions & 1 deletion generic3g/vertical/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,17 @@ target_sources(MAPL.generic3g PRIVATE
MirrorVerticalGrid.F90
FixedLevelsVerticalGrid.F90
ModelVerticalGrid.F90
)
)

esma_add_fortran_submodules(
TARGET MAPL.generic3g
SUBDIRECTORY BasicVerticalGrid
SOURCES can_connect_to.F90
)

esma_add_fortran_submodules(
TARGET MAPL.generic3g
SUBDIRECTORY ModelVerticalGrid
SOURCES can_connect_to.F90
)

10 changes: 10 additions & 0 deletions generic3g/vertical/FixedLevelsVerticalGrid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module mapl3g_FixedLevelsVerticalGrid
contains
procedure :: get_num_levels
procedure :: get_coordinate_field
procedure :: can_connect_to
end type FixedLevelsVerticalGrid

interface FixedLevelsVerticalGrid
Expand Down Expand Up @@ -58,5 +59,14 @@ subroutine get_coordinate_field(this, field, coupler, standard_name, geom, typek
_FAIL('not implemented')
end subroutine get_coordinate_field

logical function can_connect_to(this, src, rc)
class(FixedLevelsVerticalGrid), intent(in) :: this
class(VerticalGrid), intent(in) :: src
integer, optional, intent(out) :: rc

_FAIL('not implemented')

end function can_connect_to

end module mapl3g_FixedLevelsVerticalGrid

10 changes: 10 additions & 0 deletions generic3g/vertical/MirrorVerticalGrid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module mapl3g_MirrorVerticalGrid
contains
procedure :: get_num_levels
procedure :: get_coordinate_field
procedure :: can_connect_to
end type MirrorVerticalGrid

interface MirrorVerticalGrid
Expand Down Expand Up @@ -52,4 +53,13 @@ subroutine get_coordinate_field(this, field, coupler, standard_name, geom, typek
_FAIL('MirrorVerticalGrid should have been replaced before this procedure was called.')
end subroutine get_coordinate_field

logical function can_connect_to(this, src, rc)
class(MirrorVerticalGrid), intent(in) :: this
class(VerticalGrid), intent(in) :: src
integer, optional, intent(out) :: rc

can_connect_to = .false.
_RETURN(_SUCCESS)
end function

end module mapl3g_MirrorVerticalGrid
11 changes: 11 additions & 0 deletions generic3g/vertical/ModelVerticalGrid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module mapl3g_ModelVerticalGrid
contains
procedure :: get_num_levels
procedure :: get_coordinate_field
procedure :: can_connect_to

! subclass-specific methods
procedure :: add_variant
Expand All @@ -47,6 +48,14 @@ module mapl3g_ModelVerticalGrid
procedure new_ModelVerticalGrid_basic
end interface ModelVerticalGrid

interface
module function can_connect_to(this, src, rc)
logical :: can_connect_to
class(ModelVerticalGrid), intent(in) :: this
class(VerticalGrid), intent(in) :: src
integer, optional, intent(out) :: rc
end function
end interface

! TODO:
! - Ensure that there really is a vertical dimension
Expand Down Expand Up @@ -180,4 +189,6 @@ subroutine get_coordinate_field(this, field, coupler, standard_name, geom, typek

end subroutine get_coordinate_field



end module mapl3g_ModelVerticalGrid
36 changes: 36 additions & 0 deletions generic3g/vertical/ModelVerticalGrid/can_connect_to.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "MAPL_ErrLog.h"
submodule (mapl3g_ModelVerticalGrid) can_connect_to_smod
use mapl3g_BasicVerticalGrid
use mapl3g_MirrorVerticalGrid

contains

logical module function can_connect_to(this, src, rc)
use mapl3g_MirrorVerticalGrid, only: MirrorVerticalGrid
use mapl3g_BasicVerticalGrid, only: BasicVerticalGrid
class(ModelVerticalGrid), intent(in) :: this
class(VerticalGrid), intent(in) :: src
integer, optional, intent(out) :: rc

integer :: status

if (this%same_id(src)) then
can_connect_to = .true.
_RETURN(_SUCCESS)
end if

select type (src)
type is (MirrorVerticalGrid)
can_connect_to = .true.
_RETURN(_SUCCESS)
type is (BasicVerticalGrid)
can_connect_to = (this%get_num_levels() == src%get_num_levels())
_RETURN(_SUCCESS)
class default
_FAIL('unsupported subclass of VerticalGrid')
end select

_RETURN(_SUCCESS)
end function can_connect_to

end submodule
8 changes: 8 additions & 0 deletions generic3g/vertical/VerticalGrid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module mapl3g_VerticalGrid
contains
procedure(I_get_num_levels), deferred :: get_num_levels
procedure(I_get_coordinate_field), deferred :: get_coordinate_field
procedure(I_can_connect_to), deferred :: can_connect_to


procedure :: set_id
Expand Down Expand Up @@ -43,6 +44,13 @@ subroutine I_get_coordinate_field(this, field, coupler, standard_name, geom, typ
character(*), intent(in) :: units
integer, optional, intent(out) :: rc
end subroutine I_get_coordinate_field

logical function I_can_connect_to(this, src, rc) result(can_connect_to)
import VerticalGrid
class(VerticalGrid), intent(in) :: this
class(VerticalGrid), intent(in) :: src
integer, optional, intent(out) :: rc
end function I_can_connect_to

end interface

Expand Down