Skip to content

Commit

Permalink
Merge pull request #2458 from GEOS-ESM/feature/ygyu/PR_swath_2_epoch
Browse files Browse the repository at this point in the history
Swath grid for MAPL_HistoryGridComp
  • Loading branch information
mathomp4 committed Dec 1, 2023
2 parents 5f9e2e6 + af8e6a6 commit 960ffc8
Show file tree
Hide file tree
Showing 16 changed files with 3,555 additions and 50 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New directory (`docs/tutorial/grid_comps/automatic_code_generator`) containing an example showing how to automatically generate the source code using the `MAPL_GridCompSpecs_ACG.py` tool.

### Changed

- Change the verification of the grid in MAPL_GetGlobalHorzIJIndex to avoid collective call
- Swath grid step 1: allow for destroying and regenerating swath grid and regenerating regridder route handle, and creating
allocatable metadata in griddedIO. Modifications are made to GriddedIO.F90, MAPL_AbstractRegridder.F90, and MAPL_EsmfRegridder.F90.
- Swath grid step 2: add control keywords for swath grid. Allow for filename template with '*' and DOY. Allow for missing obs files. Specify index_name_lon/lat, var_name_lon/lat/time, tunit, obs_file_begin/end/interval, Epoch and Epoch_init.
- Update CI to Baselibs 7.17.0 (for future MAPL3 work) and the BCs v11.3.0 (to fix coupled run)
- Update `components.yaml`
- ESMA_env v4.22.0 (Baselibs 7.15.1)

### Fixed

- [#2433] Implemented workarounds for gfortran-13
- Missing TARGET in GriddedIO - exposed runtime error when using NAG + debug.

### Removed

Expand Down
4 changes: 2 additions & 2 deletions base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ set (srcs
MAPL_IO.F90
MAPL_LatLonGridFactory.F90 MAPL_TransposeRegridder.F90
MAPL_Comms.F90 MAPL_LatLonToLatLonRegridder.F90 MAPL_TripolarGridFactory.F90
MAPL_LlcGridFactory.F90
MAPL_LlcGridFactory.F90 MAPL_SwathGridFactory.F90
MAPL_Config.F90 MAPL_LocStreamMod.F90
MAPL_ConservativeRegridder.F90 MAPL_MaxMinMod.F90 MAPL_VerticalInterpMod.F90
MAPL_CubedSphereGridFactory.F90 MAPL_MemUtils.F90 MAPL_VerticalMethods.F90
Expand All @@ -55,7 +55,7 @@ set (srcs
MAPL_Resource.F90
MAPL_XYGridFactory.F90
MAPL_NetCDF.F90 Plain_netCDF_Time.F90
MAPL_DateTime_Parsing_ESMF.F90
MAPL_DateTime_Parsing_ESMF.F90 MAPL_ObsUtil.F90
# Orphaned program: should not be in this library.
# tstqsat.F90
)
Expand Down
52 changes: 51 additions & 1 deletion base/MAPL_AbstractGridFactory.F90
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ module MAPL_AbstractGridFactoryMod
procedure(get_file_format_vars), deferred :: get_file_format_vars
procedure(decomps_are_equal), deferred :: decomps_are_equal
procedure(physical_params_are_equal), deferred :: physical_params_are_equal

procedure :: get_xy_subset
procedure :: get_xy_mask
procedure :: destroy
procedure :: get_obs_time
end type AbstractGridFactory

abstract interface
Expand Down Expand Up @@ -238,6 +243,7 @@ function generate_file_reference3D(this,fpointer,metadata) result(ref)
type(FileMetadata), intent(in), optional :: metaData
end function generate_file_reference3D


end interface

character(len=*), parameter :: MOD_NAME = 'MAPL_AbstractGridFactory::'
Expand Down Expand Up @@ -1030,5 +1036,49 @@ function get_grid(this, unusable, rc) result(grid)
end if

end function get_grid



! This procedure should only be called for time dependent grids.
! A default implementation is to fail for other grid types, so we do not
! have to explicitly add methods to all of the existing subclasses.
subroutine get_xy_subset(this, interval, xy_subset, rc)
class(AbstractGridFactory), intent(in) :: this
type(ESMF_Time), intent(in) :: interval(2)
integer, intent(out) :: xy_subset(2,2)
integer, optional, intent(out) :: rc
integer :: status

_RETURN(_FAILURE)
end subroutine get_xy_subset

subroutine get_xy_mask(this, interval, xy_mask, rc)
class(AbstractGridFactory), intent(inout) :: this
type(ESMF_Time), intent(in) :: interval(2)
integer, allocatable, intent(out) :: xy_mask(:,:)
integer, optional, intent(out) :: rc
integer :: status

_RETURN(_FAILURE)
end subroutine get_xy_mask

! Probably don't need to do anything more for subclasses unless they have
! other objects that don't finalize well. (NetCDF, ESMF, MPI, ...)
subroutine destroy(this, rc)
class(AbstractGridFactory), intent(inout) :: this
integer, optional, intent(out) :: rc
integer :: status

call ESMF_GridDestroy(this%grid, noGarbage=.true., _RC)
_RETURN(_SUCCESS)
end subroutine destroy

subroutine get_obs_time(this, grid, obs_time, rc)
class(AbstractGridFactory), intent(inout) :: this
type (ESMF_Grid), intent(in) :: grid
real(ESMF_KIND_R4), intent(out) :: obs_time(:,:)
integer, optional, intent(out) :: rc

_RETURN(_SUCCESS)
end subroutine get_obs_time

end module MAPL_AbstractGridFactoryMod
21 changes: 21 additions & 0 deletions base/MAPL_AbstractRegridder.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module MAPL_AbstractRegridderMod
use ESMF
use MAPL_MemUtilsMod
use MAPL_ExceptionHandling
use MAPL_RegridderSpecRouteHandleMap
use, intrinsic :: iso_fortran_env, only: REAL32, REAL64
implicit none
private
Expand Down Expand Up @@ -92,6 +93,9 @@ module MAPL_AbstractRegridderMod
procedure :: has_undef_value
procedure :: get_regrid_method

procedure :: destroy
procedure :: destroy_route_handle

end type AbstractRegridder


Expand Down Expand Up @@ -1006,4 +1010,21 @@ integer function get_regrid_method(this) result(method)
method = this%spec%regrid_method
end function get_regrid_method


subroutine destroy(this, rc)
class(AbstractRegridder), intent(inout) :: this
integer, optional, intent(out) :: rc
integer :: status

_RETURN(_SUCCESS)
end subroutine destroy

subroutine destroy_route_handle(this, kind, rc)
class(AbstractRegridder), intent(inout) :: this
type(ESMF_TypeKind_Flag), intent(in) :: kind
integer, optional, intent(out) :: rc

_RETURN(_SUCCESS)
end subroutine destroy_route_handle

end module MAPL_AbstractRegridderMod
52 changes: 52 additions & 0 deletions base/MAPL_EsmfRegridder.F90
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ module MAPL_EsmfRegridderMod
procedure :: do_regrid
procedure :: create_route_handle
procedure :: select_route_handle
procedure :: destroy
procedure :: destroy_route_handle

end type EsmfRegridder

Expand Down Expand Up @@ -1600,4 +1602,54 @@ function select_route_handle(this, kind, do_transpose, rc) result(route_handle)

end function select_route_handle

subroutine destroy(this, rc)
class(EsmfRegridder), intent(inout) :: this
integer, optional, intent(out) :: rc
integer :: status

call this%destroy_route_handle(ESMF_TYPEKIND_R4, _RC)

_RETURN(_SUCCESS)
end subroutine destroy


subroutine destroy_route_handle(this, kind, rc)
class(EsmfRegridder), intent(inout) :: this
type(ESMF_TypeKind_Flag), intent(in) :: kind
integer, optional, intent(out) :: rc

type (RegridderSpec) :: spec
type(ESMF_RouteHandle) :: dummy_rh
type(RegridderSpecRouteHandleMap), pointer :: route_handles, transpose_route_handles
type(ESMF_RouteHandle) :: route_handle
type(RegridderSpecRouteHandleMapIterator) :: iter
integer :: status

if (kind == ESMF_TYPEKIND_R4) then
route_handles => route_handles_r4
transpose_route_handles => transpose_route_handles_r4
else if(kind == ESMF_TYPEKIND_R8) then
route_handles => route_handles_r8
transpose_route_handles => transpose_route_handles_r8
else
_FAIL('unsupported type kind (must be R4 or R8)')
end if

spec = this%get_spec()

_ASSERT(route_handles%count(spec) == 1, 'Did not find this spec in route handle table.')
route_handle = route_handles%at(spec)
call ESMF_RouteHandleDestroy(route_handle, noGarbage=.true.,_RC)
iter = route_handles%find(spec)
call route_handles%erase(iter)

_ASSERT(transpose_route_handles%count(spec) == 1, 'Did not find this spec in route handle table.')
route_handle = transpose_route_handles%at(spec)
call ESMF_RouteHandleDestroy(route_handle, noGarbage=.true., _RC)
iter = transpose_route_handles%find(spec)
call transpose_route_handles%erase(iter)

_RETURN(_SUCCESS)
end subroutine destroy_route_handle

end module MAPL_EsmfRegridderMod
35 changes: 30 additions & 5 deletions base/MAPL_GridManager.F90
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ module MAPL_GridManager_private
type (Integer64GridFactoryMap) :: factories
contains
procedure :: add_prototype
procedure :: destroy_grid
generic :: destroy => destroy_grid

procedure :: delete
!!$ procedure :: make_field
!!$ procedure :: delete_field
Expand Down Expand Up @@ -120,6 +123,7 @@ subroutine initialize_prototypes(this, unusable, rc)
use MAPL_LlcGridFactoryMod, only: LlcGridFactory
use MAPL_ExternalGridFactoryMod, only: ExternalGridFactory
use MAPL_XYGridFactoryMod, only: XYGridFactory
use MAPL_SwathGridFactoryMod, only : SwathGridFactory

class (GridManager), intent(inout) :: this
class (KeywordEnforcer), optional, intent(in) :: unusable
Expand All @@ -131,7 +135,8 @@ subroutine initialize_prototypes(this, unusable, rc)
type (LlcGridFactory) :: llc_factory
type (ExternalGridFactory) :: external_factory
type (XYGridFactory) :: xy_factory

type (SwathGridFactory) :: swath_factory

! This is a local variable to prevent the subroutine from running
! initialiazation twice. Calling functions have their own local variables
! to prevent calling this subroutine twice, but the initialization status
Expand All @@ -147,6 +152,7 @@ subroutine initialize_prototypes(this, unusable, rc)
call this%prototypes%insert('llc', llc_factory)
call this%prototypes%insert('External', external_factory)
call this%prototypes%insert('XY', xy_factory)
call this%prototypes%insert('Swath', swath_factory)
initialized = .true.
end if

Expand Down Expand Up @@ -397,6 +403,27 @@ function make_factory_from_distGrid(this, grid_type, dist_grid, lon_array, lat_a
end function make_factory_from_distGrid


subroutine destroy_grid(this, grid, unusable, rc)
use ESMF
class (GridManager), target, intent(inout) :: this
type (ESMF_Grid), intent(inout) :: grid
class (KeywordEnforcer), optional, intent(in) :: unusable
integer, optional, intent(out) :: rc

integer :: status
integer (kind=ESMF_KIND_I8) :: id
class(AbstractGridFactory), pointer :: factory
type(Integer64GridFactoryMapIterator) :: iter

call ESMF_AttributeGet(grid, factory_id_attribute, id, _RC)
factory => this%factories%at(id)
call factory%destroy(_RC)
iter = this%factories%find(id)
call this%factories%erase(iter)

_RETURN(_SUCCESS)
_UNUSED_DUMMY(unusable)
end subroutine destroy_grid

! Clients should use this procedure to release ESMF resources when a grid
! is no longer being used.
Expand All @@ -413,15 +440,13 @@ subroutine delete(this, grid, unusable, rc)
integer :: status
character(len=*), parameter :: Iam= MOD_NAME // 'destroy_grid'

_UNUSED_DUMMY(unusable)

if (.not. this%keep_grids) then
call ESMF_GridDestroy(grid, rc=status)
call ESMF_GridDestroy(grid, noGarbage=.true., rc=status)
_ASSERT(status==0,'failed to destroy grid')
end if

_RETURN(_SUCCESS)

_UNUSED_DUMMY(unusable)
end subroutine delete


Expand Down
Loading

0 comments on commit 960ffc8

Please sign in to comment.