Skip to content

Commit

Permalink
Convert real(kind_phys) vegetation, slope and soil type arrays into i…
Browse files Browse the repository at this point in the history
…nteger arrays without affecting input/output files (NCAR#388)

* Make real vegetation, slope and soil type integers, remove unnecessary interstitial arrays
* Add interstitial variables to save and restore vegetation/soil/slope types before/after surface physics
* Make vegetation/soil/slope save variables persistent so that they can be used in the _init phases
* Only allow nearest-neighbor interpolation method for integer data
* Remove legacy code from CMakeLists.txt
  • Loading branch information
climbfuji authored Oct 4, 2021
1 parent 799b157 commit b811a6c
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 572 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ set_target_properties(fv3atm PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT
target_include_directories(fv3atm INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/mod>
$<INSTALL_INTERFACE:mod>)

# This should not be necessary once framework and physics targets define BUILD_INTERFACE
target_include_directories(fv3atm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/ccpp/physics)

target_link_libraries(fv3atm PUBLIC fv3
fv3ccpp
stochastic_physics
Expand Down
4 changes: 2 additions & 2 deletions atmos_model.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2326,7 +2326,7 @@ subroutine assign_importdata(jdat, rc)
do i=isc,iec
nb = Atm_block%blkno(i,j)
ix = Atm_block%ixp(i,j)
GFS_data(nb)%Sfcprop%vtype(ix) = datar82d(i-isc+1,j-jsc+1)
GFS_data(nb)%Sfcprop%vtype(ix) = int(datar82d(i-isc+1,j-jsc+1))
enddo
enddo
endif
Expand All @@ -2341,7 +2341,7 @@ subroutine assign_importdata(jdat, rc)
do i=isc,iec
nb = Atm_block%blkno(i,j)
ix = Atm_block%ixp(i,j)
GFS_data(nb)%Sfcprop%stype(ix) = datar82d(i-isc+1,j-jsc+1)
GFS_data(nb)%Sfcprop%stype(ix) = int(datar82d(i-isc+1,j-jsc+1))
enddo
enddo
endif
Expand Down
491 changes: 41 additions & 450 deletions ccpp/data/GFS_typedefs.F90

Large diffs are not rendered by default.

51 changes: 24 additions & 27 deletions ccpp/data/GFS_typedefs.meta
Original file line number Diff line number Diff line change
Expand Up @@ -697,12 +697,17 @@
type = real
kind = kind_phys
[slope]
standard_name = surface_slope_classification_real
standard_name = surface_slope_classification
long_name = sfc slope type for lsm
units = index
dimensions = (horizontal_loop_extent)
type = real
kind = kind_phys
type = integer
[slope_save]
standard_name = surface_slope_classification_save
long_name = sfc slope type for lsm save
units = index
dimensions = (horizontal_loop_extent)
type = integer
[shdmin]
standard_name = min_vegetation_area_fraction
long_name = min fractional coverage of green vegetation
Expand Down Expand Up @@ -732,19 +737,29 @@
type = real
kind = kind_phys
[vtype]
standard_name = vegetation_type_classification_real
standard_name = vegetation_type_classification
long_name = vegetation type for lsm
units = index
dimensions = (horizontal_loop_extent)
type = real
kind = kind_phys
type = integer
[vtype_save]
standard_name = vegetation_type_classification_save
long_name = vegetation type for lsm save
units = index
dimensions = (horizontal_loop_extent)
type = integer
[stype]
standard_name = soil_type_classification_real
standard_name = soil_type_classification
long_name = soil type for lsm
units = index
dimensions = (horizontal_loop_extent)
type = real
kind = kind_phys
type = integer
[stype_save]
standard_name = soil_type_classification_save
long_name = soil type for lsm save
units = index
dimensions = (horizontal_loop_extent)
type = integer
[uustar]
standard_name = surface_friction_velocity
long_name = boundary layer parameter
Expand Down Expand Up @@ -9484,12 +9499,6 @@
type = real
kind = kind_phys
active = (control_for_land_surface_scheme == identifier_for_noah_wrfv4_land_surface_scheme)
[slopetype]
standard_name = surface_slope_classification
long_name = surface slope type at each grid cell
units = index
dimensions = (horizontal_loop_extent)
type = integer
[smcmax]
standard_name = soil_porosity
long_name = volumetric soil porosity
Expand Down Expand Up @@ -9590,12 +9599,6 @@
type = real
kind = kind_phys
active = (control_for_land_surface_scheme == identifier_for_noah_wrfv4_land_surface_scheme)
[soiltype]
standard_name = soil_type_classification
long_name = soil type at each grid cell
units = index
dimensions = (horizontal_loop_extent)
type = integer
[stc_save]
standard_name = soil_temperature_save
long_name = soil temperature before entering a physics scheme
Expand Down Expand Up @@ -9842,12 +9845,6 @@
dimensions = (horizontal_loop_extent)
type = real
kind = kind_phys
[vegtype]
standard_name = vegetation_type_classification
long_name = vegetation type at each grid cell
units = index
dimensions = (horizontal_loop_extent)
type = integer
[w_upi]
standard_name = vertical_velocity_for_updraft
long_name = vertical velocity for updraft
Expand Down
8 changes: 5 additions & 3 deletions ccpp/driver/GFS_diagnostics.F90
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module GFS_diagnostics

!--- private data type definition ---
type data_subtype
integer, dimension(:), pointer :: int2 => NULL()
real(kind=kind_phys), dimension(:), pointer :: var2 => NULL()
real(kind=kind_phys), dimension(:), pointer :: var21 => NULL()
real(kind=kind_phys), dimension(:,:), pointer :: var3 => NULL()
Expand Down Expand Up @@ -113,6 +114,7 @@ subroutine GFS_externaldiag_populate (ExtDiag, Model, Statein, Stateout, Sfcprop
! ExtDiag%mask [char*64 ] description of mask-type !
! ExtDiag%intpl_method [char*64 ] method to use for interpolation !
! ExtDiag%cnvfac [real*8 ] conversion factor to output specified units !
! ExtDiag%data(nb)%int2(:) [integer ] pointer to 2D data [=> null() for a 3D field] !
! ExtDiag%data(nb)%var2(:) [real*8 ] pointer to 2D data [=> null() for a 3D field] !
! ExtDiag%data(nb)%var21(:) [real*8 ] pointer to 2D data for ratios !
! ExtDiag%data(nb)%var3(:,:) [real*8 ] pointer to 3D data [=> null() for a 2D field] !
Expand Down Expand Up @@ -2610,7 +2612,7 @@ subroutine GFS_externaldiag_populate (ExtDiag, Model, Statein, Stateout, Sfcprop
ExtDiag(idx)%mod_name = 'gfs_sfc'
allocate (ExtDiag(idx)%data(nblks))
do nb = 1,nblks
ExtDiag(idx)%data(nb)%var2 => Sfcprop(nb)%slope(:)
ExtDiag(idx)%data(nb)%int2 => Sfcprop(nb)%slope(:)
enddo

idx = idx + 1
Expand Down Expand Up @@ -2724,7 +2726,7 @@ subroutine GFS_externaldiag_populate (ExtDiag, Model, Statein, Stateout, Sfcprop
ExtDiag(idx)%mod_name = 'gfs_sfc'
allocate (ExtDiag(idx)%data(nblks))
do nb = 1,nblks
ExtDiag(idx)%data(nb)%var2 => Sfcprop(nb)%stype(:)
ExtDiag(idx)%data(nb)%int2 => Sfcprop(nb)%stype(:)
enddo

idx = idx + 1
Expand Down Expand Up @@ -2819,7 +2821,7 @@ subroutine GFS_externaldiag_populate (ExtDiag, Model, Statein, Stateout, Sfcprop
ExtDiag(idx)%mod_name = 'gfs_sfc'
allocate (ExtDiag(idx)%data(nblks))
do nb = 1,nblks
ExtDiag(idx)%data(nb)%var2 => sfcprop(nb)%vtype(:)
ExtDiag(idx)%data(nb)%int2 => sfcprop(nb)%vtype(:)
enddo

idx = idx + 1
Expand Down
35 changes: 35 additions & 0 deletions cpl/module_block_data.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module module_block_data
implicit none

interface block_data_copy
module procedure block_copy_1d_i4_to_2d_r8
module procedure block_copy_1d_to_2d_r8
module procedure block_copy_2d_to_2d_r8
module procedure block_copy_2d_to_3d_r8
Expand Down Expand Up @@ -50,6 +51,40 @@ module module_block_data

! -- copy: 1D to 2D

subroutine block_copy_1d_i4_to_2d_r8(destin_ptr, source_ptr, block, block_index, scale_factor, rc)

! -- arguments
real(ESMF_KIND_R8), pointer :: destin_ptr(:,:)
integer, pointer :: source_ptr(:)
type(block_control_type), intent(in) :: block
integer, intent(in) :: block_index
real(kind_phys), optional, intent(in) :: scale_factor
integer, optional, intent(out) :: rc

! -- local variables
integer :: localrc
integer :: i, ib, ix, j, jb
real(kind_phys) :: factor

! -- begin
localrc = ESMF_RC_PTR_NOTALLOC
if (associated(destin_ptr) .and. associated(source_ptr)) then
factor = 1._kind_phys
if (present(scale_factor)) factor = scale_factor
do ix = 1, block%blksz(block_index)
ib = block%index(block_index)%ii(ix)
jb = block%index(block_index)%jj(ix)
i = ib - block%isc + 1
j = jb - block%jsc + 1
destin_ptr(i,j) = factor * real(source_ptr(ix), kind=kind_phys)
enddo
localrc = ESMF_SUCCESS
end if

if (present(rc)) rc = localrc

end subroutine block_copy_1d_i4_to_2d_r8

subroutine block_copy_1d_to_2d_r8(destin_ptr, source_ptr, block, block_index, scale_factor, rc)

! -- arguments
Expand Down
Loading

0 comments on commit b811a6c

Please sign in to comment.