Skip to content

Commit

Permalink
Move lonCell wrap code to dyn_grid.F90 from cam_mpas_subdriver.F90
Browse files Browse the repository at this point in the history
This commit also extends the comment that was with this code block,
includes an if condition so valid values aren't modified, uses kinds and
constants (pi) that are already used in the new file, and updates the
ChangeLog so the correct file is referenced.
  • Loading branch information
gdicker1 committed Jul 26, 2024
1 parent 288f3ed commit fabe37a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions doc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ List all files eliminated: N/A
List all files added and what they do: N/A

List all existing files that have been modified, and describe the changes:
M src/dynamics/mpas/driver/cam_mpas_subdriver.F90
- Modifies cam_mpas_read_static to ensure lonCell values are in [0,2pi) range
M src/dynamics/mpas/dyn_grid.F90
- Modifies setup_time_invariant to ensure lonCell values are in [0,2pi) range

If there were any failures reported from running test_driver.sh on any test
platform, and checkin with these failures has been OK'd by the gatekeeper,
Expand Down
13 changes: 2 additions & 11 deletions src/dynamics/mpas/driver/cam_mpas_subdriver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -884,16 +884,15 @@ subroutine cam_mpas_read_static(fh_ini, endrun)

use pio, only : file_desc_t

use mpas_kind_types, only : StrKIND, RKIND
use mpas_kind_types, only : StrKIND
use mpas_io_streams, only : MPAS_createStream, MPAS_closeStream, MPAS_streamAddField, MPAS_readStream
use mpas_derived_types, only : MPAS_IO_READ, MPAS_IO_NETCDF, MPAS_Stream_type, MPAS_pool_type, &
field0DReal, field1DReal, field2DReal, field3DReal, field1DInteger, field2DInteger, &
MPAS_STREAM_NOERR
use mpas_pool_routines, only : MPAS_pool_get_subpool, MPAS_pool_get_field, MPAS_pool_create_pool, MPAS_pool_destroy_pool, &
MPAS_pool_add_config, MPAS_pool_get_array
MPAS_pool_add_config
use mpas_dmpar, only : MPAS_dmpar_exch_halo_field
use mpas_stream_manager, only : postread_reindex
use mpas_constants, only : pii

! Arguments
type (file_desc_t), pointer :: fh_ini
Expand Down Expand Up @@ -930,11 +929,8 @@ subroutine cam_mpas_read_static(fh_ini, endrun)

type (MPAS_Stream_type) :: mesh_stream

real(kind=RKIND), dimension(:), pointer :: lonCell_arr

nullify(cell_gradient_coef_x)
nullify(cell_gradient_coef_y)
nullify(lonCell_arr)

call MPAS_createStream(mesh_stream, domain_ptr % ioContext, 'not_used', MPAS_IO_NETCDF, MPAS_IO_READ, &
pio_file_desc=fh_ini, ierr=ierr)
Expand Down Expand Up @@ -1175,11 +1171,6 @@ subroutine cam_mpas_read_static(fh_ini, endrun)
call endrun(subname//': FATAL: Failed to close static input stream.')
end if

call mpas_pool_get_array(meshPool, 'lonCell', lonCell_arr)

! Ensure longitudes w/i [0, 2*pi) range
lonCell_arr(:) = lonCell_arr(:) - (2._RKIND*pii) * floor(lonCell_arr(:) / (2._RKIND*pii))

!
! Perform halo updates for all decomposed fields (i.e., fields with
! an outermost dimension of nCells, nVertices, or nEdges)
Expand Down
13 changes: 13 additions & 0 deletions src/dynamics/mpas/dyn_grid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ subroutine setup_time_invariant(fh_ini)
type(mpas_pool_type), pointer :: meshPool
real(r8), pointer :: rdzw(:)
real(r8), allocatable :: dzw(:)
integer, pointer :: nCells
real(r8), dimension(:), pointer :: lonCell

integer :: k, kk
integer :: ierr
Expand All @@ -473,6 +475,7 @@ subroutine setup_time_invariant(fh_ini)
call mpas_pool_get_dimension(meshPool, 'nEdgesSolve', nEdgesSolve)
call mpas_pool_get_dimension(meshPool, 'nVerticesSolve', nVerticesSolve)
call mpas_pool_get_dimension(meshPool, 'nVertLevels', nVertLevelsSolve) ! MPAS always solves over the full column
call mpas_pool_get_dimension(meshPool, 'nCells', nCells)

! check that number of vertical layers matches MPAS grid data
if (plev /= nVertLevelsSolve) then
Expand All @@ -482,6 +485,16 @@ subroutine setup_time_invariant(fh_ini)
') does not match plev ('//int2str(nVertLevelsSolve)//').')
end if

! Ensure longitudes are within the [0,2*pi) range, and only remap values that
! are outside the range. Some non-simple physics in CAM require this
! longitude range, MPAS may have any (radian) value in lonCell
call mpas_pool_get_array(meshPool, 'lonCell', lonCell)
do k=1,nCells
if (lonCell(k) < 0._r8 .or. lonCell(k) .ge. (2._r8 * pi)) then
lonCell(k) = lonCell(k) - (2._r8 * pi) * floor(lonCell(k) / (2._r8 * pi))
end if
end do

! Initialize fields needed for reconstruction of cell-centered winds from edge-normal winds
! Note: This same pair of calls happens a second time later in the initialization of
! the MPAS-A dycore (in atm_mpas_init_block), but the redundant calls do no harm
Expand Down

0 comments on commit fabe37a

Please sign in to comment.