Skip to content

Commit

Permalink
Merge pull request #3148 from GEOS-ESM/feature/tclune/#3146-merge-fie…
Browse files Browse the repository at this point in the history
…ld-subdirs

Fixes #3146 and #3144
  • Loading branch information
tclune authored Nov 4, 2024
2 parents f0cdea1 + 88f2800 commit 5d0ec60
Show file tree
Hide file tree
Showing 54 changed files with 364 additions and 618 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ add_subdirectory (pfio)
add_subdirectory (profiler)
add_subdirectory (generic)
add_subdirectory (generic3g)
add_subdirectory (field_utils)
add_subdirectory (field)
add_subdirectory (oomph) # temporary - will rename to generic when done
add_subdirectory (shared)
Expand Down
2 changes: 1 addition & 1 deletion MAPL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ esma_set_this()

esma_add_library (${this}
SRCS MAPL.F90
DEPENDENCIES MAPL.base MAPL.generic MAPL.pfio MAPL_cfio_r4 MAPL.gridcomps MAPL.orbit MAPL.griddedio MAPL.field_utils ${EXTDATA_TARGET}
DEPENDENCIES MAPL.base MAPL.generic MAPL.pfio MAPL_cfio_r4 MAPL.gridcomps MAPL.orbit MAPL.griddedio MAPL.field ${EXTDATA_TARGET}
ESMF::ESMF NetCDF::NetCDF_Fortran MPI::MPI_Fortran
TYPE SHARED
)
Expand Down
2 changes: 1 addition & 1 deletion base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ endif()

esma_add_library(
${this} SRCS ${srcs}
DEPENDENCIES MAPL.shared MAPL.constants MAPL.profiler MAPL.pfio MAPL_cfio_r4 MAPL.field_utils PFLOGGER::pflogger
DEPENDENCIES MAPL.shared MAPL.constants MAPL.profiler MAPL.pfio MAPL_cfio_r4 MAPL.field PFLOGGER::pflogger
GFTL_SHARED::gftl-shared-v2 GFTL_SHARED::gftl-shared-v1 GFTL::gftl-v2 GFTL::gftl-v1
ESMF::ESMF NetCDF::NetCDF_Fortran MPI::MPI_Fortran
TYPE SHARED)
Expand Down
3 changes: 1 addition & 2 deletions esmf_utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ set(srcs

esma_add_library(${this}
SRCS ${srcs}
DEPENDENCIES MAPL.shared
DEPENDENCIES MAPL.shared ESMF::ESMF
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)
Expand Down
13 changes: 10 additions & 3 deletions esmf_utils/FieldDimensionInfo.F90
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,18 @@ integer function get_num_levels_info(info, rc) result(num)
integer, optional, intent(out) :: rc
integer :: status
character(len=:), allocatable :: spec_name
integer :: num_field_levels

num = 0
spec_name = get_vertical_dim_spec_info(info, _RC)
_RETURN_IF(spec_name == VERT_DIM_NONE)
call MAPL_InfoGet(info, key=KEY_NUM_LEVELS, value=num, _RC)
_RETURN_IF(spec_name == "VERTICAL_STAGGER_NONE")
call MAPL_InfoGet(info, key=KEY_NUM_LEVELS, value=num_field_levels, _RC)

if (spec_name == "VERTICAL_STAGGER_EDGE") then
num = num_field_levels - 1
else
num = num_field_levels
end if

_RETURN(_SUCCESS)
end function get_num_levels_info
Expand Down Expand Up @@ -153,7 +160,7 @@ function get_vertical_dim_spec_info(info, rc) result(spec_name)
integer :: status
logical :: isPresent

call MAPL_InfoGet(info, key=KEY_VLOC, value=spec_name, _RC)
call MAPL_InfoGet(info, key=KEY_VERT_STAGGERLOC, value=spec_name, _RC)
isPresent = ESMF_InfoIsPresent(info, key=KEY_VLOC, _RC)

_RETURN(_SUCCESS)
Expand Down
2 changes: 1 addition & 1 deletion esmf_utils/UngriddedDims.F90
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function make_info(this, rc) result(info)
character(:), allocatable :: dim_key

info = ESMF_InfoCreate(_RC)
call MAPL_InfoSet(info, key='num_ungridded_dimensions', value=this%get_num_ungridded(), _RC)
call MAPL_InfoSet(info, key='/num_ungridded_dimensions', value=this%get_num_ungridded(), _RC)

do i = 1, this%get_num_ungridded()
dim_spec => this%get_ith_dim_spec(i, _RC)
Expand Down
43 changes: 16 additions & 27 deletions esmf_utils/tests/Test_FieldDimensionInfo.pf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Test_FieldDimensionInfo
implicit none

integer, parameter :: NUM_LEVELS_DEFAULT = 3
character(len=*), parameter :: VLOC_DEFAULT = 'VERTICAL_DIM_CENTER'
character(len=*), parameter :: VERT_STAGGER_DEFAULT = 'VERTICAL_STAGGER_CENTER'
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 @@ -48,16 +48,16 @@ contains
@Test
subroutine test_get_vertical_dim_spec_names()
integer :: status
character(len=*), parameter :: EXPECTED_NAME_1 = 'VERTICAL_DIM_CENTER'
character(len=*), parameter :: EXPECTED_NAME_2 = 'VERTICAL_DIM_EDGE'
character(len=*), parameter :: EXPECTED_NAME_1 = 'VERTICAL_STAGGER_CENTER'
character(len=*), parameter :: EXPECTED_NAME_2 = 'VERTICAL_STAGGER_EDGE'
type(StringVector), allocatable :: names
integer :: sz

call safe_dealloc(bundle_info)
allocate(bundle_info(3))
bundle_info(1) = make_esmf_info(vloc=EXPECTED_NAME_1, _RC)
bundle_info(2) = make_esmf_info(vloc=EXPECTED_NAME_2, _RC)
bundle_info(3) = make_esmf_info(vloc=EXPECTED_NAME_1, _RC)
bundle_info(1) = make_esmf_info(vert_stagger=EXPECTED_NAME_1, _RC)
bundle_info(2) = make_esmf_info(vert_stagger=EXPECTED_NAME_2, _RC)
bundle_info(3) = make_esmf_info(vert_stagger=EXPECTED_NAME_1, _RC)
names = get_vertical_dim_spec_names_bundle_info(bundle_info, _RC)
sz = names%size()
@assertEqual(2, sz, 'There should only be two unique vertical_dim_spec names.')
Expand Down Expand Up @@ -107,28 +107,28 @@ contains

end subroutine test_get_ungridded_dims

function make_esmf_info(num_levels, vloc, num_ungridded, names, units_array, coordinates, rc) &
function make_esmf_info(num_levels, vert_stagger, num_ungridded, names, units_array, coordinates, rc) &
result(info)
type(ESMF_Info) :: info
integer, optional, intent(in) :: num_levels
character(len=*), optional, intent(in) :: vloc
character(len=*), optional, intent(in) :: vert_stagger
integer, optional, intent(in) :: num_ungridded
character(len=*), optional, intent(in) :: names(:)
character(len=*), optional, intent(in) :: units_array(:)
real, optional, intent(in) :: coordinates(:, :)
integer, optional, intent(out) :: rc
integer :: status
integer :: num_levels_, num_ungridded_
character(len=:), allocatable :: vloc_
character(len=:), allocatable :: vert_stagger_

num_ungridded_ = -1
num_levels_ = NUM_LEVELS_DEFAULT
if(present(num_levels)) num_levels_ = num_levels
vloc_ = VLOC_DEFAULT
if(present(vloc)) vloc_ = vloc
vert_stagger_ = VERT_STAGGER_DEFAULT
if(present(vert_stagger)) vert_stagger_ = vert_stagger
info = ESMF_InfoCreate(_RC)
call make_vertical_dim(info, vloc_, _RC)
call make_vertical_geom(info, num_levels_, _RC)
call make_vertical_dim(info, vert_stagger_, _RC)
call ESMF_InfoSet(info, KEY_NUM_LEVELS, num_levels_, _RC)

SET_RC(status)

Expand All @@ -145,28 +145,17 @@ contains

end function make_esmf_info

subroutine make_vertical_dim(info, vloc, rc)
subroutine make_vertical_dim(info, vert_stagger, rc)
type(ESMF_Info), intent(inout) :: info
character(len=*), intent(in) :: vloc
character(len=*), intent(in) :: vert_stagger
integer, optional, intent(out) :: rc
integer :: status

call ESMF_InfoSet(info, KEY_VLOC, vloc, _RC)
call ESMF_InfoSet(info, KEY_VERT_STAGGERLOC, vert_stagger, _RC)
SET_RC(status)

end subroutine make_vertical_dim

subroutine make_vertical_geom(info, num_levels, rc)
type(ESMF_Info), intent(inout) :: info
integer, intent(in) :: num_levels
integer, optional, intent(out) :: rc
integer :: status

call ESMF_InfoSet(info, KEY_NUM_LEVELS, num_levels, _RC)
SET_RC(status)

end subroutine make_vertical_geom

subroutine make_ungridded_dims_info(info, num_ungridded, names, units_array, coordinates, rc)
type(ESMF_Info), intent(inout) :: info
integer, intent(in) :: num_ungridded
Expand Down
18 changes: 17 additions & 1 deletion field/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ esma_set_this (OVERRIDE MAPL.field)

set(srcs
API.F90
FieldUtils.F90
FieldBLAS.F90
FieldPointerUtilities.F90
FieldDelta.F90
FieldUtilities.F90
FieldUnaryFunctions.F90
FieldBinaryOperations.F90
FieldUnits.F90
FieldCondensedArray.F90
FieldCondensedArray_private.F90
FieldDelta.F90
FieldBundleDelta.F90
VerticalStaggerLoc.F90
FieldCreate.F90
FieldReset.F90
Expand All @@ -11,9 +23,13 @@ set(srcs

list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")

if (BUILD_WITH_PFLOGGER)
find_package (PFLOGGER REQUIRED)
endif ()

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

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 21 additions & 16 deletions field_utils/FieldBundleDelta.F90 → field/FieldBundleDelta.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ module mapl3g_FieldBundleDelta
use mapl3g_LU_Bound
use mapl3g_FieldDelta
use mapl3g_InfoUtilities
use mapl3g_VerticalStaggerLoc
use mapl3g_FieldCreate
use mapl3g_FieldGet
use mapl3g_FieldInfo
use mapl_FieldUtilities
use mapl3g_UngriddedDims
use mapl_FieldPointerUtilities
use mapl3g_esmf_info_keys
use mapl3g_esmf_info_keys, only: KEY_INTERPOLATION_WEIGHTS
use mapl_ErrorHandling
use mapl_KeywordEnforcer
use esmf
Expand Down Expand Up @@ -205,11 +210,12 @@ subroutine reallocate_bundle(this, bundle, ignore, unusable, rc)
type(ESMF_TypeKind_Flag) :: typekind
integer, allocatable :: ungriddedLbound(:), ungriddedUbound(:)
type(ESMF_Info) :: ungridded_info
type(ESMF_Info) :: vertical_info
integer :: old_field_count, new_field_count
integer :: num_levels
character(:), allocatable :: units, vloc
integer, allocatable :: num_levels
character(:), allocatable :: units, vert_staggerloc_str
type(VerticalStaggerLoc) :: vert_staggerloc
character(ESMF_MAXSTR), allocatable :: fieldNameList(:)
type(UngriddedDims) :: ungridded_dims

! Easy case 1: field count unchanged
call MAPL_FieldBundleGet(bundle, fieldList=fieldList, _RC)
Expand All @@ -233,28 +239,27 @@ subroutine reallocate_bundle(this, bundle, ignore, unusable, rc)

! Need geom, typekind, and bounds to allocate fields before
call MAPL_FieldBundleGet(bundle, geom=bundle_geom, _RC)
call MAPL_FieldBundleGet(bundle, typekind=typekind, ungriddedUBound=ungriddedUbound, _RC)
ungriddedLBound = [(1, i = 1, size(ungriddedUBound))]
call MAPL_FieldBundleGet(bundle, typekind=typekind, _RC)

ungridded_info = MAPL_InfoCreateFromInternal(bundle, key=KEY_UNGRIDDED_DIMS, _RC)
ungridded_dims = make_UngriddedDims(ungridded_info, _RC)
call MAPL_InfoGetInternal(bundle, KEY_UNITS, value=units, _RC)

call MAPL_InfoGetInternal(bundle, KEY_VLOC, value=vloc, _RC)
if (vloc /= "VERTICAL_DIM_NONE") then
call MAPL_InfoGetInternal(bundle, KEY_VERT_STAGGERLOC, value=vert_staggerloc_str, _RC)
vert_staggerloc = VerticalStaggerLoc(vert_staggerloc_str)
_ASSERT(vert_staggerloc /= VERTICAL_STAGGER_INVALID, 'Vert stagger is INVALID.')
if (vert_staggerloc /= VERTICAL_STAGGER_NONE) then
allocate(num_levels)
call MAPL_InfoGetInternal(bundle, KEY_NUM_LEVELS, value=num_levels, _RC)
end if

do i = 1, new_field_count
fieldList(i) = ESMF_FieldEmptyCreate(_RC)
call ESMF_FieldEmptySet(fieldList(i), geom=bundle_geom, _RC)
call ESMF_FieldEmptyComplete(fieldList(i), typekind=typekind, &
ungriddedLbound=ungriddedLBound, ungriddedUbound=ungriddedUBound, _RC)
call MAPL_InfoSetInternal(fieldList(i), KEY_UNGRIDDED_DIMS, value=ungridded_info, _RC)
call MAPL_InfoSetInternal(fieldList(i), KEY_VLOC, value=vloc, _RC)
if (vloc /= "VERTICAL_DIM_NONE") then
call MAPL_InfoSetInternal(fieldList(i), KEY_NUM_LEVELS, value=num_levels, _RC)
end if
call MAPL_InfoSetInternal(fieldList(i), KEY_UNITS, value=units, _RC)
call MAPL_FieldEmptyComplete(fieldList(i), typekind=typekind, &
ungridded_dims=ungridded_dims, &
num_levels=num_levels, vert_staggerLoc=vert_staggerLoc, &
units=units, _RC)
end do

call ESMF_InfoDestroy(ungridded_info, _RC)
Expand Down
File renamed without changes.
File renamed without changes.
36 changes: 16 additions & 20 deletions field_utils/FieldDelta.F90 → field/FieldDelta.F90
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

#include "MAPL_Exceptions.h"
module mapl3g_FieldDelta
use mapl3g_FieldInfo
use mapl3g_FieldGet
use mapl3g_VerticalStaggerLoc
use mapl3g_InfoUtilities
use mapl_FieldPointerUtilities
use mapl3g_esmf_info_keys
use mapl_ErrorHandling
use mapl_KeywordEnforcer
use esmf
Expand Down Expand Up @@ -152,8 +154,8 @@ subroutine compute_num_levels_delta(num_levels, f_a, f_b, rc)
integer :: status
integer :: num_levels_a, num_levels_b

call MAPL_InfoGetInternal(f_a, key=KEY_NUM_LEVELS, value=num_levels_a, _RC)
call MAPL_InfoGetInternal(f_b, key=KEY_NUM_LEVELS, value=num_levels_b, _RC)
call MAPL_FieldGet(f_a, num_levels=num_levels_a, _RC)
call MAPL_FieldGet(f_b, num_levels=num_levels_b, _RC)

if (num_levels_a /= num_levels_b) then
num_levels = num_levels_b
Expand All @@ -172,8 +174,8 @@ subroutine compute_units_delta(units, f_a, f_b, rc)
integer :: status
character(len=:), allocatable :: units_a, units_b

call MAPL_InfoGetInternal(f_a, KEY_UNITS, value=units_a, _RC)
call MAPL_InfoGetInternal(f_b, KEY_UNITS, value=units_b, _RC)
call MAPL_FieldGet(f_a, units=units_a, _RC)
call MAPL_FieldGet(f_b, units=units_b, _RC)

if (units_a /= units_b) then
allocate(character(len_trim(units_b)) :: units)
Expand All @@ -200,8 +202,7 @@ subroutine initialize_field_delta_degenerate(this, f, rc)
call ESMF_FieldGet(f, geom=this%geom, typekind=typekind, _RC)

allocate(this%num_levels)
call MAPL_InfoGetInternal(f, KEY_NUM_LEVELS, value=this%num_levels, _RC)
call MAPL_InfoGetInternal(f, KEY_UNITS, value=this%units, _RC)
call MAPL_FieldGet(f, num_levels=this%num_levels, units=this%units, _RC)

_RETURN(_SUCCESS)
end subroutine initialize_field_delta_degenerate
Expand Down Expand Up @@ -372,7 +373,7 @@ subroutine select_ungriddedUbound(ungriddedUbound, field, new_num_levels, ignore
integer, optional, intent(inout) :: rc

integer :: status
character(:), allocatable :: vloc
type(VerticalStaggerLoc) :: vert_staggerloc
integer :: ungriddedDimCount
integer :: rank
integer :: current_num_levels
Expand All @@ -389,22 +390,17 @@ subroutine select_ungriddedUbound(ungriddedUbound, field, new_num_levels, ignore
if (ignore == 'num_levels') return
if (.not. present(new_num_levels)) return

call MAPL_InfoGetInternal(field, KEY_NUM_LEVELS, value=current_num_levels, _RC)
call MAPL_InfoGetInternal(field, KEY_VLOC, value=vloc, _RC)
call MAPL_FieldGet(field, vert_staggerloc=vert_staggerloc, _RC)

! Surface fields are not impacted by change in vertical grid
_RETURN_IF(vloc == 'VERTICAL_DIM_NONE')
_RETURN_IF(vert_staggerloc == VERTICAL_STAGGER_NONE)

new_array = new_array .or. (this%num_levels /= current_num_levels)

select case (vloc)
case ('VERTICAL_DIM_CENTER')
ungriddedUBound(1) = this%num_levels
case ('VERTICAL_DIM_EDGE')
ungriddedUBound(1) = this%num_levels + 1
case default
_FAIL('unsupported vertical location: '//vloc)
end select
call MAPL_FieldGet(field, num_levels=current_num_levels, _RC)
_ASSERT(count(vert_staggerloc == [VERTICAL_STAGGER_CENTER, VERTICAL_STAGGER_EDGE]) == 1, 'unsupported vertical stagger')
ungriddedUBound(1) = this%num_levels

new_array = new_array .or. (this%num_levels /= current_num_levels)

_RETURN(_SUCCESS)
end subroutine select_ungriddedUbound
Expand Down
Loading

0 comments on commit 5d0ec60

Please sign in to comment.