Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/core_atmosphere/Registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,16 @@
units="-"
description="Whether to print the global min/max of scalar fields each timestep"
possible_values=".true. or .false."/>

<nml_option name="config_print_global_minmax_tend_ps" type="logical" default_value="false"
units="-"
description="Whether to print the global min/max of surface-pressure tendency each timestep"
possible_values=".true. or .false."/>

<nml_option name="config_print_detailed_minmax_tend_ps" type="logical" default_value="false"
units="-"
description="Whether to print the global min/max of surface-pressure tendency each timestep, along with the location in the domain where those extrema occurred"
possible_values=".true. or .false."/>
</nml_record>

<nml_record name="IAU" in_defaults="true">
Expand Down
130 changes: 130 additions & 0 deletions src/core_atmosphere/dynamics/mpas_atm_time_integration.F
Original file line number Diff line number Diff line change
Expand Up @@ -8702,6 +8702,8 @@ subroutine summarize_timestep(domain)
logical, pointer :: config_print_global_minmax_vel
logical, pointer :: config_print_detailed_minmax_vel
logical, pointer :: config_print_global_minmax_sca
logical, pointer :: config_print_global_minmax_tend_ps
logical, pointer :: config_print_detailed_minmax_tend_ps

integer :: iCell, k, iEdge, iScalar
integer, pointer :: num_scalars_ptr, nCellsSolve_ptr, nEdgesSolve_ptr, nVertLevels_ptr
Expand All @@ -8710,6 +8712,7 @@ subroutine summarize_timestep(domain)
type (mpas_pool_type), pointer :: state
type (mpas_pool_type), pointer :: diag
type (mpas_pool_type), pointer :: mesh
type (mpas_pool_type), pointer :: tend

real (kind=RKIND) :: scalar_min, scalar_max
real (kind=RKIND) :: global_scalar_min, global_scalar_max
Expand All @@ -8733,6 +8736,7 @@ subroutine summarize_timestep(domain)
real (kind=RKIND), dimension(:,:), pointer :: w
real (kind=RKIND), dimension(:,:), pointer :: u, v, uReconstructZonal, uReconstructMeridional, uReconstructX, uReconstructY, uReconstructZ
real (kind=RKIND), dimension(:,:,:), pointer :: scalars, scalars_1, scalars_2
real (kind=RKIND), dimension(:), pointer :: tend_sfc_pressure
real (kind=RKIND), dimension(:,:), pointer :: rho_zz, wwavg, uhAvg, zz
real (kind=RKIND), dimension(:), pointer :: rdzw, rdzu, fzm, fzp
integer, dimension(:,:), pointer :: cellsOnEdge
Expand All @@ -8743,13 +8747,17 @@ subroutine summarize_timestep(domain)
call mpas_pool_get_config(block % configs, 'config_print_global_minmax_vel', config_print_global_minmax_vel)
call mpas_pool_get_config(block % configs, 'config_print_detailed_minmax_vel', config_print_detailed_minmax_vel)
call mpas_pool_get_config(block % configs, 'config_print_global_minmax_sca', config_print_global_minmax_sca)
call mpas_pool_get_config(block % configs, 'config_print_global_minmax_tend_ps', config_print_global_minmax_tend_ps)
call mpas_pool_get_config(block % configs, 'config_print_detailed_minmax_tend_ps', config_print_detailed_minmax_tend_ps)

call mpas_pool_get_subpool(block % structs, 'state', state)
call mpas_pool_get_subpool(block % structs, 'diag', diag)
call mpas_pool_get_subpool(block % structs, 'tend', tend)
call mpas_pool_get_array(state, 'w', w, 2)
call mpas_pool_get_array(state, 'u', u, 2)
call mpas_pool_get_array(diag, 'v', v)
call mpas_pool_get_array(state, 'scalars', scalars, 2)
call mpas_pool_get_array(tend, 'tend_sfc_pressure', tend_sfc_pressure)
call mpas_pool_get_dimension(state, 'nCellsSolve', nCellsSolve_ptr)
call mpas_pool_get_dimension(state, 'nEdgesSolve', nEdgesSolve_ptr)
call mpas_pool_get_dimension(state, 'nVertLevels', nVertLevels_ptr)
Expand Down Expand Up @@ -9117,6 +9125,128 @@ subroutine summarize_timestep(domain)

end if

if (config_print_detailed_minmax_tend_ps) then
if (.not. (config_print_global_minmax_vel .or. config_print_detailed_minmax_vel .or. &
config_print_global_minmax_sca) ) then
call mpas_log_write('')
end if

call mpas_pool_get_subpool(block % structs, 'mesh', mesh)

call mpas_pool_get_array(mesh, 'indexToCellID', indexToCellID)
call mpas_pool_get_array(mesh, 'latCell', latCell)
call mpas_pool_get_array(mesh, 'lonCell', lonCell)

scalar_min = 1.0e20
offset_1d = huge(1)
indexMax = -1
latMax = 0.0
lonMax = 0.0
!$acc parallel default(present)
!$acc loop collapse(2) gang vector reduction(min:scalar_min)
do iCell = 1, nCellsSolve
Comment on lines +9145 to +9147
scalar_min = min(scalar_min, tend_sfc_pressure(iCell))
end do
!$acc end parallel

! This second loop using offset_1d ensures the same (indexMax) are reported with the scalar_min
! Especially when using OpenACC
!$acc parallel default(present)
!$acc loop collapse(2) gang vector reduction(min:offset_1d)
do iCell = 1, nCellsSolve
if (tend_sfc_pressure(iCell) == scalar_min) then
! In case 2 locations tie, only save the minimum value
offset_1d = min(offset_1d, iCell-1) ! modified for 2D spatial (horizontal) variable (dimension size "1" in vertical)
end if
end do
!$acc end parallel
indexMax = offset_1d + 1 ! modified for 2D spatial (horizontal) variable
latMax = latCell(indexMax)
lonMax = lonCell(indexMax)
localVals(1) = scalar_min
localVals(2) = real(indexMax,kind=RKIND)
localVals(3) = 1._RKIND ! kMax = "1"
localVals(4) = latMax
localVals(5) = lonMax
call mpas_dmpar_minattributes_real(domain % dminfo, scalar_min, localVals, globalVals)
global_scalar_min = globalVals(1)
indexMax_global = int(globalVals(2))
kMax_global = int(globalVals(3))
latMax_global = globalVals(4)
lonMax_global = globalVals(5)
latMax_global = latMax_global * 180.0_RKIND / pi_const
lonMax_global = lonMax_global * 180.0_RKIND / pi_const
if (lonMax_global > 180.0) then
lonMax_global = lonMax_global - 360.0
end if
! format statement should be '(a,f9.4,a,f7.3,a,f8.3,a)'
call mpas_log_write(' global min tend_sfc_pressure: $r $r lat, $r lon', &
realArgs=(/global_scalar_min, latMax_global, lonMax_global/))

scalar_max = -1.0e20
offset_1d = huge(1)
indexMax = -1
kMax = -1
latMax = 0.0
lonMax = 0.0
!$acc parallel default(present)
!$acc loop collapse(2) gang vector reduction(max:scalar_max)
do iCell = 1, nCellsSolve
scalar_max = max(scalar_max, tend_sfc_pressure(iCell))
end do
!$acc end parallel

!$acc parallel default(present)
!$acc loop collapse(2) gang vector reduction(min:offset_1d)
do iCell = 1, nCellsSolve
if (tend_sfc_pressure(iCell) == scalar_max) then
offset_1d = min(offset_1d, iCell-1)
end if
end do
!$acc end parallel
indexMax = offset_1d + 1
latMax = latCell(indexMax)
lonMax = lonCell(indexMax)
localVals(1) = scalar_max
localVals(2) = real(indexMax,kind=RKIND)
localVals(3) = 1._RKIND
localVals(4) = latMax
localVals(5) = lonMax
call mpas_dmpar_maxattributes_real(domain % dminfo, scalar_max, localVals, globalVals)
global_scalar_max = globalVals(1)
indexMax_global = int(globalVals(2))
kMax_global = int(globalVals(3))
latMax_global = globalVals(4)
lonMax_global = globalVals(5)
latMax_global = latMax_global * 180.0_RKIND / pi_const
lonMax_global = lonMax_global * 180.0_RKIND / pi_const
if (lonMax_global > 180.0) then
lonMax_global = lonMax_global - 360.0
end if
! format statement should be '(a,f9.4,a,f7.3,a,f8.3,a)'
call mpas_log_write(' global max tend_sfc_pressure: $r $r lat, $r lon', &
realArgs=(/global_scalar_max, latMax_global, lonMax_global/))

else if (config_print_global_minmax_tend_ps ) then
if (.not. (config_print_global_minmax_vel .or. config_print_detailed_minmax_vel .or. &
config_print_global_minmax_sca) ) then
call mpas_log_write('')
end if

scalar_min = 0.0
scalar_max = 0.0
!$acc parallel default(present)
!$acc loop gang vector collapse(2) reduction(min:scalar_min) reduction(max:scalar_max)
do iCell = 1, nCellsSolve
scalar_min = min(scalar_min, tend_sfc_pressure(iCell))
scalar_max = max(scalar_max, tend_sfc_pressure(iCell))
end do
!$acc end parallel
call mpas_dmpar_min_real(domain % dminfo, scalar_min, global_scalar_min)
call mpas_dmpar_max_real(domain % dminfo, scalar_max, global_scalar_max)
call mpas_log_write('global min, max tend_sfc_pressure $r $r', realArgs=(/global_scalar_min, global_scalar_max/))
end if

end subroutine summarize_timestep

end module atm_time_integration
Loading