Skip to content

Commit cfb8098

Browse files
committed
Compute temperature and spechum at output times via diagnostics
1 parent c10ba4d commit cfb8098

7 files changed

Lines changed: 171 additions & 6 deletions

File tree

src/core_atmosphere/Registry.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,8 +1767,7 @@
17671767
description="Relative humidity"/>
17681768

17691769
<var name="spechum" type="real" dimensions="nVertLevels nCells Time" units="kg kg^{-1}"
1770-
description="Specific humidity"
1771-
packages="jedi_da"/>
1770+
description="Specific humidity"/>
17721771

17731772
<var name="v" type="real" dimensions="nVertLevels nEdges Time" units="m s^{-1}"
17741773
description="Horizontal tangential velocity at edges"/>

src/core_atmosphere/diagnostics/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ DIAGNOSTIC_MODULES = \
1010
mpas_convective_diagnostics.o \
1111
mpas_pv_diagnostics.o \
1212
mpas_soundings.o \
13+
mpas_modellevel_diagnostics.o \
1314

1415
mpas_isobaric_diagnostics.o: mpas_atm_diagnostics_utils.o
1516

@@ -21,6 +22,7 @@ mpas_pv_diagnostics.o: mpas_atm_diagnostics_utils.o
2122

2223
mpas_soundings.o:
2324

25+
mpas_modellevel_diagnostics.o: mpas_atm_diagnostics_utils.o
2426

2527
################### Generally no need to modify below here ###################
2628

src/core_atmosphere/diagnostics/Registry_diagnostics.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
<!-- soundings -->
2020
#include "Registry_soundings.xml"
2121

22+
<!-- additional model-level diagnostics -->
23+
#include "Registry_modellevel.xml"
24+
2225
<!-- ******************************* -->
2326
<!-- End includes from diagnostics -->
2427
<!-- ******************************* -->
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!-- ******************************************* -->
2+
<!-- Diagnostics for model-level height surfaces -->
3+
<!-- ******************************************* -->
4+
5+
<!-- temperature and spechum are already added in core_atmosphere/Registry.xml -->
6+
7+
<!-- <var_struct name="diag" time_levs="1">
8+
9+
<var name="temperature" type="real" dimensions="nVertLevels nCells Time" units="K"
10+
description="temperature" />
11+
12+
<var name="spechum" type="real" dimensions="nVertLevels nCells Time" units="kg kg^{-1}"
13+
description="specific humidity"/>
14+
15+
</var_struct> -->

src/core_atmosphere/diagnostics/mpas_atm_diagnostics_manager.F

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ subroutine mpas_atm_diag_setup(stream_mgr, configs, structs, clock, dminfo)
3838
use mpas_convective_diagnostics, only : convective_diagnostics_setup
3939
use mpas_pv_diagnostics, only : pv_diagnostics_setup
4040
use mpas_soundings, only : soundings_setup
41+
use mpas_modellevel_diagnostics, only : modellevel_diagnostics_setup
4142

4243
implicit none
4344

@@ -59,6 +60,7 @@ subroutine mpas_atm_diag_setup(stream_mgr, configs, structs, clock, dminfo)
5960
call convective_diagnostics_setup(structs, clock)
6061
call pv_diagnostics_setup(structs, clock)
6162
call soundings_setup(configs, structs, clock, dminfo)
63+
call modellevel_diagnostics_setup(structs, clock)
6264

6365
end subroutine mpas_atm_diag_setup
6466

@@ -105,6 +107,7 @@ subroutine mpas_atm_diag_compute()
105107
use mpas_convective_diagnostics, only : convective_diagnostics_compute
106108
use mpas_pv_diagnostics, only : pv_diagnostics_compute
107109
use mpas_soundings, only : soundings_compute
110+
use mpas_modellevel_diagnostics, only : modellevel_diagnostics_compute
108111

109112
implicit none
110113

@@ -115,6 +118,7 @@ subroutine mpas_atm_diag_compute()
115118
call convective_diagnostics_compute()
116119
call pv_diagnostics_compute()
117120
call soundings_compute()
121+
call modellevel_diagnostics_compute()
118122

119123
end subroutine mpas_atm_diag_compute
120124

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
! Copyright (c) 2022, University Corporation for Atmospheric Research (UCAR).
2+
!
3+
! Unless noted otherwise source code is licensed under the BSD license.
4+
! Additional copyright and license information can be found in the LICENSE file
5+
! distributed with this code, or at https://mpas-dev.github.io/license.html
6+
!
7+
module mpas_modellevel_diagnostics
8+
9+
use mpas_derived_types, only : MPAS_pool_type, MPAS_clock_type
10+
use mpas_kind_types, only : RKIND
11+
use mpas_constants, only : rvord
12+
13+
type (MPAS_pool_type), pointer :: mesh
14+
type (MPAS_pool_type), pointer :: state
15+
type (MPAS_pool_type), pointer :: diag
16+
!type (MPAS_pool_type), pointer :: diag_physics
17+
18+
type (MPAS_clock_type), pointer :: clock
19+
20+
public :: modellevel_diagnostics_setup, &
21+
modellevel_diagnostics_compute
22+
23+
private
24+
25+
26+
contains
27+
28+
29+
!-----------------------------------------------------------------------
30+
! routine modellevel_diagnostics_setup
31+
!
32+
!> \brief Initialize the modellevel diagnostic module
33+
!> \author Jihyeon Jang
34+
!> \date 30 January 2026
35+
!> \details
36+
!> Initialize the diagnostic and save pointers to subpools for
37+
!> reuse in this module
38+
!
39+
!-----------------------------------------------------------------------
40+
subroutine modellevel_diagnostics_setup(all_pools, simulation_clock)
41+
42+
use mpas_derived_types, only : MPAS_pool_type, MPAS_clock_type
43+
use mpas_pool_routines, only : mpas_pool_get_subpool
44+
45+
implicit none
46+
47+
type (MPAS_pool_type), pointer :: all_pools
48+
type (MPAS_clock_type), pointer :: simulation_clock
49+
50+
clock => simulation_clock
51+
52+
call mpas_pool_get_subpool(all_pools, 'mesh', mesh)
53+
call mpas_pool_get_subpool(all_pools, 'state', state)
54+
call mpas_pool_get_subpool(all_pools, 'diag', diag)
55+
56+
!call mpas_pool_get_array(diag, 'temperature', temperature)
57+
!call mpas_pool_get_array(diag, 'spechum', spechum)
58+
!
59+
! Zero-out the initial field
60+
!
61+
!temperature(:,:) = 0.0_RKIND
62+
!spechum(:,:) = 0.0_RKIND
63+
64+
end subroutine modellevel_diagnostics_setup
65+
66+
67+
!-----------------------------------------------------------------------
68+
! routine modellevel_diagnostics_compute
69+
!
70+
!> \brief Compute diagnostic before model output is written
71+
!> \author Jihyeon Jang
72+
!> \date 30 January 2026
73+
!> \details
74+
!> Compute diagnostic before model output is written
75+
!> The following fields are computed by this routine:
76+
!> temperature
77+
!> spechum
78+
!
79+
!-----------------------------------------------------------------------
80+
subroutine modellevel_diagnostics_compute()
81+
82+
use mpas_atm_diagnostics_utils, only : MPAS_field_will_be_written
83+
use mpas_pool_routines, only : mpas_pool_get_dimension, mpas_pool_get_array
84+
85+
implicit none
86+
87+
integer :: iCell, k
88+
integer :: time_lev
89+
integer, pointer :: nCellsSolve, nVertLevels
90+
integer, pointer :: index_qv
91+
92+
real (kind=RKIND), dimension(:,:), pointer :: temperature
93+
real (kind=RKIND), dimension(:,:), pointer :: spechum
94+
real (kind=RKIND), dimension(:,:), pointer :: exner, theta_m
95+
real (kind=RKIND), dimension(:,:,:), pointer :: scalars
96+
97+
logical :: need_ml_diags, need_temperature, need_spechum
98+
99+
time_lev = 1
100+
101+
need_ml_diags = .false.
102+
need_temperature = MPAS_field_will_be_written('temperature')
103+
need_ml_diags = need_ml_diags .or. need_temperature
104+
need_spechum = MPAS_field_will_be_written('spechum')
105+
need_ml_diags = need_ml_diags .or. need_spechum
106+
107+
108+
if (need_ml_diags) then
109+
call mpas_pool_get_dimension(mesh, 'nCellsSolve', nCellsSolve)
110+
call mpas_pool_get_dimension(mesh, 'nVertLevels', nVertLevels)
111+
end if
112+
113+
if (need_temperature .or. need_spechum) then
114+
call mpas_pool_get_dimension(state, 'index_qv', index_qv)
115+
call mpas_pool_get_array(state, 'scalars', scalars, time_lev)
116+
end if
117+
118+
if (need_temperature) then
119+
call mpas_pool_get_array(state, 'theta_m', theta_m, time_lev)
120+
call mpas_pool_get_array(diag, 'exner', exner)
121+
call mpas_pool_get_array(diag, 'temperature', temperature)
122+
end if
123+
124+
if (need_spechum) then
125+
call mpas_pool_get_array(diag, 'spechum', spechum)
126+
end if
127+
128+
if (need_temperature) then
129+
do iCell=1,nCellsSolve
130+
do k=1,nVertLevels
131+
temperature(k,iCell) = (theta_m(k,iCell)/(1._RKIND+rvord*scalars(index_qv,k,iCell)))*exner(k,iCell)
132+
end do
133+
end do
134+
end if
135+
136+
if (need_spechum) then
137+
do iCell=1,nCellsSolve
138+
do k=1,nVertLevels
139+
spechum(k,iCell) = scalars(index_qv,k,iCell) / (1.0_RKIND+scalars(index_qv,k,iCell))
140+
end do
141+
end do
142+
end if
143+
144+
end subroutine modellevel_diagnostics_compute
145+
146+
end module mpas_modellevel_diagnostics

src/core_atmosphere/mpas_atm_core.F

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,6 @@ subroutine atm_compute_output_diagnostics(state, time_lev, diag, mesh)
918918
integer, pointer :: nCells, nVertLevels, index_qv
919919
real (kind=RKIND), dimension(:,:), pointer :: theta, rho, theta_m, rho_zz, zz
920920
real (kind=RKIND), dimension(:,:), pointer :: pressure_base, pressure_p, pressure
921-
real (kind=RKIND), dimension(:,:), pointer :: exner, temperature
922921
real (kind=RKIND), dimension(:,:,:), pointer :: scalars
923922

924923
call mpas_pool_get_dimension(mesh, 'nCells', nCells)
@@ -934,8 +933,6 @@ subroutine atm_compute_output_diagnostics(state, time_lev, diag, mesh)
934933
call mpas_pool_get_array(diag, 'pressure_p', pressure_p)
935934
call mpas_pool_get_array(diag, 'pressure_base', pressure_base)
936935
call mpas_pool_get_array(diag, 'pressure', pressure)
937-
call mpas_pool_get_array(diag, 'exner', exner)
938-
call mpas_pool_get_array(diag, 'temperature', temperature)
939936

940937
call mpas_pool_get_array(mesh, 'zz', zz)
941938

@@ -944,7 +941,6 @@ subroutine atm_compute_output_diagnostics(state, time_lev, diag, mesh)
944941
theta(k,iCell) = theta_m(k,iCell) / (1._RKIND + rvord * scalars(index_qv,k,iCell))
945942
rho(k,iCell) = rho_zz(k,iCell) * zz(k,iCell)
946943
pressure(k,iCell) = pressure_base(k,iCell) + pressure_p(k,iCell)
947-
temperature(k,iCell) = theta(k,iCell) * exner(k,iCell)
948944
end do
949945
end do
950946

0 commit comments

Comments
 (0)