Skip to content

Commit

Permalink
Merge branch 'release/MAPL-v3' into feature/pchakrab/vertical-regridding
Browse files Browse the repository at this point in the history
  • Loading branch information
pchakraborty committed Sep 24, 2024
2 parents 2fcce7f + 50f6be6 commit feb55fa
Show file tree
Hide file tree
Showing 19 changed files with 556 additions and 201 deletions.
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added capability for HistoryCollectionGridComp to extract field names from expressions
- Added ability for HistoryCollectionGridComp to extract multiple field names from expressions
- Added vertical and ungridded dimensions to output for History3G
- Create rank-agnostic representation of `ESMF_Field` objects as rank-3 array pointers.

### Changed

Expand All @@ -62,6 +63,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

### Changed

### Fixed

### Removed

### Deprecated

## [2.48.0] - 2024-09-24

### Added

- Added 5 new ExtData tests to test compression, bit-shaving, and quantization

### Changed
Expand Down Expand Up @@ -114,8 +127,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix profiler PercentageColumn test for GCC 14
- Fix bug in ExtData Tests. CMake was overwriting the `EXTDATA2G_SMALL_TESTS` LABEL with `ESSENTIAL`

### Removed

### Deprecated

- Deprecate `GranularBR` as a quantization method keyword in History. We will prefer `granular_bitround` in the future to match
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ endif ()

project (
MAPL
VERSION 2.47.2
VERSION 2.48.0
LANGUAGES Fortran CXX C) # Note - CXX is required for ESMF

# Set the possible values of build type for cmake-gui
Expand Down
2 changes: 1 addition & 1 deletion GeomIO/SharedIO.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module mapl3g_SharedIO
use MAPL_BaseMod
use mapl3g_UngriddedDims
use mapl3g_UngriddedDim
use mapl3g_output_info
use mapl3g_FieldDimensionInfo

implicit none

Expand Down
1 change: 0 additions & 1 deletion base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ set (srcs
MAPL_XYGridFactory.F90
MAPL_NetCDF.F90 Plain_netCDF_Time.F90
MAPL_DateTime_Parsing_ESMF.F90 MAPL_ObsUtil.F90
MAPL_ESMF_InfoKeys.F90
# Orphaned program: should not be in this library.
# tstqsat.F90
)
Expand Down
7 changes: 5 additions & 2 deletions esmf_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
esma_set_this (OVERRIDE MAPL.esmf_utils)

set(srcs
OutputInfo.F90
FieldDimensionInfo.F90
UngriddedDim.F90
UngriddedDims.F90
UngriddedDimVector.F90
Expand All @@ -10,11 +10,14 @@ set(srcs

esma_add_library(${this}
SRCS ${srcs}
DEPENDENCIES MAPL.shared MAPL.base
DEPENDENCIES MAPL.shared
TYPE SHARED
)

target_include_directories (${this} PUBLIC
$<BUILD_INTERFACE:${MAPL_SOURCE_DIR}/include>)
target_link_libraries (${this} PUBLIC ESMF::ESMF)

if (PFUNIT_FOUND)
add_subdirectory(tests)
endif ()
49 changes: 24 additions & 25 deletions esmf_utils/OutputInfo.F90 → esmf_utils/FieldDimensionInfo.F90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "MAPL_Generic.h"
module mapl3g_output_info
module mapl3g_FieldDimensionInfo

use mapl3g_UngriddedDim
use mapl3g_UngriddedDimVector
Expand All @@ -10,8 +10,8 @@ module mapl3g_output_info
use esmf, only: ESMF_Info, ESMF_InfoIsPresent
use esmf, only: ESMF_InfoDestroy, ESMF_InfoCreate
use esmf, only: ESMF_InfoGet, ESMF_InfoGetFromHost
use esmf, only: ESMF_InfoGetAlloc, ESMF_InfoGetCharAlloc
use esmf, only: ESMF_InfoPrint
use esmf, only: ESMF_InfoGetAlloc, ESMF_InfoPrint
use esmf, only: ESMF_MAXSTR, ESMF_SUCCESS
use Mapl_ErrorHandling

implicit none
Expand Down Expand Up @@ -93,12 +93,11 @@ integer function get_num_levels_info(info, rc) result(num)
type(ESMF_Info), intent(in) :: info
integer, optional, intent(out) :: rc
integer :: status
logical :: is_none
character(len=:), allocatable :: spec_name

num = 0
is_none = VERT_DIM_NONE == get_vertical_dim_spec_info(info, _RC)
_RETURN_IF(is_none)

spec_name = get_vertical_dim_spec_info(info, _RC)
_RETURN_IF(spec_name == VERT_DIM_NONE)
call ESMF_InfoGet(info, key=KEY_NUM_LEVELS, value=num, _RC)
_RETURN(_SUCCESS)

Expand All @@ -123,12 +122,12 @@ function get_vertical_dim_spec_names_bundle_info(info, rc) result(names)
integer, optional, intent(out) :: rc
integer :: status
integer :: i
character(len=:), allocatable :: name
character(len=:), allocatable :: spec_name

names = StringVector()
do i=1, size(info)
name = get_vertical_dim_spec_info(info(i), _RC)
if(find_index(names, name) == 0) call names%push_back(name)
spec_name = get_vertical_dim_spec_info(info(i), _RC)
if(find_index(names, spec_name) == 0) call names%push_back(spec_name)
end do
_RETURN(_SUCCESS)

Expand All @@ -152,8 +151,14 @@ function get_vertical_dim_spec_info(info, rc) result(spec_name)
type(ESMF_Info), intent(in) :: info
integer, optional, intent(out) :: rc
integer :: status
logical :: isPresent
character(len=ESMF_MAXSTR) :: raw

isPresent = ESMF_InfoIsPresent(info, key=KEY_VLOC, _RC)
_ASSERT(isPresent, 'Failed to get vertical dim spec name.')
call ESMF_InfoGet(info, key=KEY_VLOC, value=raw, _RC)
spec_name = trim(adjustl(raw))

call ESMF_InfoGetCharAlloc(info, key=KEY_VLOC, value=spec_name, _RC)
_RETURN(_SUCCESS)

end function get_vertical_dim_spec_info
Expand Down Expand Up @@ -225,8 +230,9 @@ function make_ungridded_dim(info, n, rc) result(ungridded_dim)
type(ESMF_Info), intent(in) :: info
integer, optional, intent(out) :: rc
integer :: status
character(len=:), allocatable :: key
type(ESMF_Info) :: dim_info
character(len=ESMF_MAXSTR) :: raw
character(len=:), allocatable :: key
character(len=:), allocatable :: name
character(len=:), allocatable :: units
real, allocatable :: coordinates(:)
Expand All @@ -237,11 +243,13 @@ function make_ungridded_dim(info, n, rc) result(ungridded_dim)
call ESMF_InfoGet(info, key=key, isPresent=is_present, _RC)
if(.not. is_present) then
call ESMF_InfoPrint(info, unit=json_repr, _RC)
_FAIL('Key ' // trim(key) // ' not found in ' // trim(json_repr))
end if
_ASSERT(is_present, 'Key ' // key // ' not found in ' // trim(json_repr))
dim_info = ESMF_InfoCreate(info, key=key, _RC)
call ESMF_InfoGetCharAlloc(dim_info, key=KEY_UNGRIDDED_NAME, value=name, _RC)
call ESMF_InfoGetCharAlloc(dim_info, key=KEY_UNGRIDDED_UNITS, value=units, _RC)
call ESMF_InfoGet(dim_info, key=KEY_UNGRIDDED_NAME, value=raw, _RC)
name = trim(adjustl(raw))
call ESMF_InfoGet(dim_info, key=KEY_UNGRIDDED_UNITS, value=raw, _RC)
units = trim(adjustl(raw))
call ESMF_InfoGetAlloc(dim_info, key=KEY_UNGRIDDED_COORD, values=coordinates, _RC)
call ESMF_InfoDestroy(dim_info, _RC)
ungridded_dim = UngriddedDim(coordinates, name=name, units=units)
Expand Down Expand Up @@ -284,7 +292,6 @@ subroutine check_duplicate(vec, udim, rc)
class(UngriddedDimVector), intent(in) :: vec
class(UngriddedDim), intent(in) :: udim
integer, optional, intent(out) :: rc
integer :: status
type(UngriddedDimVectorIterator) :: iter
type(UngriddedDim) :: vdim

Expand All @@ -300,20 +307,12 @@ subroutine check_duplicate(vec, udim, rc)

end subroutine check_duplicate

logical function is_vertical_dim_none(s)
character(len=*), intent(in) :: s

is_vertical_dim_none = s == 'VERTICAL_DIM_NONE'

end function is_vertical_dim_none

function create_bundle_info(bundle, rc) result(bundle_info)
type(ESMF_Info), allocatable :: bundle_info(:)
type(ESMF_FieldBundle), intent(in) :: bundle
integer, optional, intent(out) :: rc
integer :: status
integer :: field_count, i
type(ESMF_Field) :: field
type(ESMF_Field), allocatable :: fields(:)
type(ESMF_Info) :: info

Expand Down Expand Up @@ -343,4 +342,4 @@ subroutine destroy_bundle_info(bundle_info, rc)

end subroutine destroy_bundle_info

end module mapl3g_output_info
end module mapl3g_FieldDimensionInfo
25 changes: 25 additions & 0 deletions esmf_utils/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
set(MODULE_DIRECTORY "${esma_include}/MAPL.esmf_utils.tests")

set (test_srcs
Test_FieldDimensionInfo.pf
)

add_pfunit_ctest(MAPL.esmf_utils.tests
TEST_SOURCES ${test_srcs}
LINK_LIBRARIES MAPL.esmf_utils MAPL.pfunit
EXTRA_INITIALIZE Initialize
EXTRA_USE MAPL_pFUnit_Initialize
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
MAX_PES 1
)
set_target_properties(MAPL.esmf_utils.tests PROPERTIES Fortran_MODULE_DIRECTORY ${MODULE_DIRECTORY})
set_tests_properties(MAPL.esmf_utils.tests PROPERTIES LABELS "ESSENTIAL")

if (APPLE)
set(LD_PATH "DYLD_LIBRARY_PATH")
else()
set(LD_PATH "LD_LIBRARY_PATH")
endif ()
set_property(TEST MAPL.esmf_utils.tests PROPERTY ENVIRONMENT "${LD_PATH}=${CMAKE_CURRENT_BINARY_DIR}/esmf_utils:$ENV{${LD_PATH}}")

add_dependencies(build-tests MAPL.esmf_utils.tests)
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#define _SUCCESS 0
#define _FAILURE _SUCCESS-1
#include "MAPL_TestErr.h"
module Test_OutputInfo
use mapl3g_output_info
module Test_FieldDimensionInfo
use mapl3g_FieldDimensionInfo
use mapl3g_esmf_info_keys
use mapl3g_UngriddedDim
use mapl3g_UngriddedDimVector
Expand All @@ -16,10 +16,8 @@ module Test_OutputInfo

implicit none

integer, parameter :: NUM_FIELDS_DEFAULT = 2
integer, parameter :: NUM_LEVELS_DEFAULT = 3
character(len=*), parameter :: VLOC_DEFAULT = 'VERTICAL_DIM_CENTER'
integer, parameter :: NUM_UNGRIDDED_DEFAULT = 3
character(len=*), parameter :: NAME_DEFAULT = 'A1'
character(len=*), parameter :: UNITS_DEFAULT = 'stones'
real, parameter :: COORDINATES_DEFAULT(*) = [2.0, 2.4, 2.5]
Expand Down Expand Up @@ -250,4 +248,4 @@ contains
if(allocated(info)) call deallocate_destroy(info)
end subroutine safe_dealloc

end module Test_OutputInfo
end module Test_FieldDimensionInfo
5 changes: 4 additions & 1 deletion field_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ set(srcs
FieldUnaryFunctions.F90
FieldBinaryOperations.F90
FieldUnits.F90
FieldCondensedArray.F90
FieldCondensedArray_private.F90
)

# To use extended udunits2 procedures, udunits2.c must be built and linked.
Expand All @@ -24,9 +26,10 @@ endif ()

esma_add_library(${this}
SRCS ${srcs}
DEPENDENCIES MAPL.shared PFLOGGER::pflogger udunits2f
DEPENDENCIES MAPL.shared MAPL.esmf_utils PFLOGGER::pflogger udunits2f
TYPE SHARED
)
#DEPENDENCIES MAPL.shared PFLOGGER::pflogger udunits2f

#add_subdirectory(specs)
#add_subdirectory(registry)
Expand Down
72 changes: 72 additions & 0 deletions field_utils/FieldCondensedArray.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "MAPL_Generic.h"
module mapl3g_FieldCondensedArray
use, intrinsic :: iso_c_binding, only: c_ptr, c_f_pointer
use mapl3g_FieldCondensedArray_private, only: ARRAY_RANK, get_shape => get_fptr_shape
use mapl3g_FieldDimensionInfo, only: get_vertical_dim_spec_name
use MAPL_FieldPointerUtilities, only: FieldGetLocalElementCount, assign_fptr
use MAPL_ExceptionHandling
use ESMF, only: ESMF_Field, ESMF_FieldGet
use ESMF, only: ESMF_KIND_R4, ESMF_KIND_R8, ESMF_KIND_I8

implicit none
private
public :: assign_fptr_condensed_array

interface assign_fptr_condensed_array
module procedure :: assign_fptr_condensed_array_r4
module procedure :: assign_fptr_condensed_array_r8
end interface assign_fptr_condensed_array

contains

subroutine assign_fptr_condensed_array_r4(x, fptr, rc)
type(ESMF_Field), intent(inout) :: x
real(kind=ESMF_KIND_R4), pointer, intent(out) :: fptr(:,:,:)
integer, optional, intent(out) :: rc
integer(ESMF_KIND_I8) :: fp_shape(ARRAY_RANK)
integer :: status

fp_shape = get_fptr_shape(x, _RC)
call assign_fptr(x, fp_shape, fptr, _RC)
_RETURN(_SUCCESS)

end subroutine assign_fptr_condensed_array_r4

subroutine assign_fptr_condensed_array_r8(x, fptr, rc)
type(ESMF_Field), intent(inout) :: x
real(kind=ESMF_KIND_R8), pointer, intent(out) :: fptr(:,:,:)
integer, optional, intent(out) :: rc
integer(ESMF_KIND_I8) :: fp_shape(ARRAY_RANK)
integer :: status

fp_shape = get_fptr_shape(x, _RC)
call assign_fptr(x, fp_shape, fptr, _RC)
_RETURN(_SUCCESS)

end subroutine assign_fptr_condensed_array_r8

function get_fptr_shape(f, rc) result(fptr_shape)
integer :: fptr_shape(ARRAY_RANK)
type(ESMF_Field), intent(inout) :: f
integer, optional, intent(out) :: rc
integer :: status
integer :: rank
integer, allocatable :: gridToFieldMap(:)
integer, allocatable :: localElementCount(:)
logical :: has_vertical
character(len=:), allocatable :: spec_name
character(len=*), parameter :: VERTICAL_DIM_NONE_NAME = 'VERTICAL_DIM_NONE'

call ESMF_FieldGet(f, gridToFieldMap=gridToFieldMap, _RC)
call ESMF_FieldGet(f, rank=rank, _RC)
allocate(localElementCount(rank))
! Due to an ESMF bug, getting the localElementCount must use the module function.
! See FieldGetLocalElementCount (specific function) comments.
localElementCount = FieldGetLocalElementCount(f, _RC)
spec_name = get_vertical_dim_spec_name(f, _RC)
has_vertical = spec_name /= VERTICAL_DIM_NONE_NAME
fptr_shape = get_shape(gridToFieldMap, localElementCount, has_vertical, _RC)

end function get_fptr_shape

end module mapl3g_FieldCondensedArray
Loading

0 comments on commit feb55fa

Please sign in to comment.