Skip to content

Commit 0d7919c

Browse files
committed
Add constituent hooks to remaining analytic IC options.
1 parent fa0b5e1 commit 0d7919c

File tree

3 files changed

+130
-67
lines changed

3 files changed

+130
-67
lines changed

src/dynamics/tests/initial_conditions/ic_baro_dry_jw06.F90

Lines changed: 64 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ module ic_baro_dry_jw06
5050

5151
subroutine bc_dry_jw06_set_ic(vcoord, latvals, lonvals, U, V, T, PS, PHIS, &
5252
Q, m_cnst, mask, verbose)
53-
use dyn_tests_utils, only: vc_moist_pressure, vc_dry_pressure, vc_height
54-
use cam_constituents, only: const_get_index
55-
!use constituents, only: cnst_name
56-
!use const_init, only: cnst_init_default
53+
use shr_kind_mod, only: cx => shr_kind_cx
54+
use dyn_tests_utils, only: vc_moist_pressure, vc_dry_pressure, vc_height
55+
use runtime_obj, only: wv_stdname
56+
use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t
57+
use cam_ccpp_cap, only: cam_model_const_properties
58+
use ccpp_kinds, only: kind_phys
59+
use cam_constituents, only: const_get_index, const_qmin
5760

5861
!-----------------------------------------------------------------------
5962
!
@@ -79,23 +82,31 @@ subroutine bc_dry_jw06_set_ic(vcoord, latvals, lonvals, U, V, T, PS, PHIS, &
7982
logical, allocatable :: mask_use(:)
8083
logical :: verbose_use
8184
logical :: lu,lv,lt,lq,l3d_vars
85+
logical :: const_has_default
8286
integer :: i, k, m
8387
integer :: ncol
8488
integer :: nlev
8589
integer :: ncnst
8690
integer :: iret
87-
integer :: ix_rain, ix_cld_liq
91+
integer :: ix_q, m_cnst_ix_q
8892
character(len=*), parameter :: subname = 'BC_DRY_JW06_SET_IC'
93+
character(len=cx) :: errmsg !CCPP error message
8994
real(r8) :: tmp
9095
real(r8) :: r(size(latvals))
9196
real(r8) :: eta
9297
real(r8) :: factor
9398
real(r8) :: perturb_lon, perturb_lat
9499
real(r8) :: phi_vertical
95100
real(r8) :: u_wind(size(latvals))
101+
real(kind_phys) :: const_default_value !Constituent default value
102+
real(kind_phys) :: const_qmin_value !Constituent minimum value
96103

97-
a_omega = rearth*omega
98-
exponent = rair*gamma/gravit
104+
!Private array of constituent properties (for property interface functions)
105+
type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:)
106+
107+
!Set local constants:
108+
a_omega = rearth*omega
109+
exponent = rair*gamma/gravit
99110

100111
allocate(mask_use(size(latvals)), stat=iret)
101112
call check_allocate(iret, subname, 'mask_use(size(latvals))', &
@@ -116,10 +127,6 @@ subroutine bc_dry_jw06_set_ic(vcoord, latvals, lonvals, U, V, T, PS, PHIS, &
116127
verbose_use = .true.
117128
end if
118129

119-
!set constituent indices
120-
call const_get_index('cloud_liquid_water_mixing_ratio_wrt_moist_air_and_condensed_water', ix_cld_liq)
121-
call const_get_index('rain_mixing_ratio_wrt_moist_air_and_condensed_water', ix_rain)
122-
123130
ncol = size(latvals, 1)
124131
nlev = -1
125132

@@ -236,40 +243,63 @@ subroutine bc_dry_jw06_set_ic(vcoord, latvals, lonvals, U, V, T, PS, PHIS, &
236243
end if
237244
end if
238245
if (lq) then
246+
!Get water vapor constituent index:
247+
call const_get_index(wv_stdname, ix_q)
248+
249+
!Determine which "Q" variable index matches water vapor:
250+
m_cnst_ix_q = findloc(m_cnst, ix_q, dim=1)
251+
239252
do k = 1, nlev
240253
where(mask_use)
241-
Q(:,k,1) = 0.0_r8
254+
Q(:,k,m_cnst_ix_q) = 0.0_r8
242255
end where
243256
end do
244-
!Un-comment once constituents are working in CAMDEN -JN:
245-
#if 0
246257
if(masterproc.and. verbose_use) then
247-
write(iulog,*) ' ', trim(cnst_name(m_cnst(1))), ' initialized by "',subname,'"'
258+
write(iulog,*) ' ', wv_stdname, ' initialized by "',subname,'"'
248259
end if
249-
#endif
250260
end if
251261
end if
252262

253-
!Un-comment once constituents are working in CAMDEN -JN:
254-
#if 0
255-
if (lq) then
256-
ncnst = size(m_cnst, 1)
257-
if ((vcoord == vc_moist_pressure) .or. (vcoord == vc_dry_pressure)) then
258-
do m = 2, ncnst
259-
call cnst_init_default(m_cnst(m), latvals, lonvals, Q(:,:,m_cnst(m)),&
260-
mask=mask_use, verbose=verbose_use, notfound=.false.)
261-
end do
262-
end if
263-
end if
264-
#else
265263
if (lq) then
264+
ncnst = size(m_cnst)
266265
if ((vcoord == vc_moist_pressure) .or. (vcoord == vc_dry_pressure)) then
267-
!Initialize cloud liquid and rain until constituent routines are enabled:
268-
Q(:,:,ix_cld_liq) = 0.0_r8
269-
Q(:,:,ix_rain) = 0.0_r8
270-
end if
271-
end if
272-
#endif
266+
do m = 1, ncnst
267+
268+
!Skip water vapor, as it was aleady set above:
269+
if (m == m_cnst_ix_q) cycle
270+
271+
!Extract constituent minimum value:
272+
const_qmin_value = const_qmin(m_cnst(m))
273+
274+
!Initialize constituent to its minimum value:
275+
Q(:,:,m) = real(const_qmin_value, r8)
276+
277+
if (iret /= 0) then
278+
call endrun(errmsg, file=__FILE__, line=__LINE__)
279+
end if
280+
281+
if (const_has_default) then
282+
283+
!If default value exists, then extract default value
284+
!from constituent properties object:
285+
call const_props(m_cnst(m))%default_value(const_default_value, &
286+
iret, &
287+
errmsg)
288+
if (iret /= 0) then
289+
call endrun(errmsg, file=__FILE__, line=__LINE__)
290+
end if
291+
292+
!Set constituent to default value in masked region:
293+
do k=1,nlev
294+
where(mask_use)
295+
Q(:,k,m) = real(const_default_value, r8)
296+
end where
297+
end do
298+
299+
end if !has_default
300+
end do !m_cnst
301+
end if !lq
302+
end if !l3d_vars
273303

274304
deallocate(mask_use)
275305

src/dynamics/tests/initial_conditions/ic_us_standard_atm.F90

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,6 @@ module ic_us_standard_atmosphere
77
!
88
!-------------------------------------------------------------------------------
99

10-
use shr_kind_mod, only: r8 => shr_kind_r8
11-
use spmd_utils, only: masterproc
12-
13-
use hycoef, only: ps0, hyam, hybm
14-
use physconst, only: gravit
15-
!use constituents, only: cnst_name
16-
!use const_init, only: cnst_init_default
17-
18-
use std_atm_profile, only: std_atm_pres, std_atm_height, std_atm_temp
19-
20-
use cam_logfile, only: iulog
21-
use cam_abortutils, only: endrun, check_allocate
22-
2310
implicit none
2411
private
2512
save
@@ -33,6 +20,19 @@ module ic_us_standard_atmosphere
3320
subroutine us_std_atm_set_ic(latvals, lonvals, zint, U, V, T, PS, PHIS_IN, &
3421
PHIS_OUT, Q, m_cnst, mask, verbose)
3522

23+
use shr_kind_mod, only: r8 => shr_kind_r8, cx => shr_kind_cx
24+
use ccpp_kinds, only: kind_phys
25+
use spmd_utils, only: masterproc
26+
use hycoef, only: ps0, hyam, hybm
27+
use physconst, only: gravit
28+
use std_atm_profile, only: std_atm_pres, std_atm_height, std_atm_temp
29+
use cam_logfile, only: iulog
30+
use cam_abortutils, only: endrun, check_allocate
31+
use runtime_obj, only: wv_stdname
32+
use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t
33+
use cam_ccpp_cap, only: cam_model_const_properties
34+
use cam_constituents, only: const_get_index, const_qmin
35+
3636
!----------------------------------------------------------------------------
3737
!
3838
! Set initial values for static atmosphere with vertical profile from US
@@ -58,14 +58,22 @@ subroutine us_std_atm_set_ic(latvals, lonvals, zint, U, V, T, PS, PHIS_IN, &
5858
! Local variables
5959
logical, allocatable :: mask_use(:)
6060
logical :: verbose_use
61+
logical :: const_has_default
6162
integer :: i, k, m
6263
integer :: ncol
6364
integer :: nlev, nlevp
6465
integer :: ncnst
6566
integer :: iret
67+
integer :: ix_q, m_cnst_ix_q
6668
character(len=*), parameter :: subname = 'us_std_atm_set_ic'
69+
character(len=cx) :: errmsg !CCPP error message
6770
real(r8) :: psurf(1)
6871
real(r8), allocatable :: pmid(:), zmid(:), zmid2d(:,:)
72+
real(kind_phys) :: const_default_value !Constituent default value
73+
real(kind_phys) :: const_qmin_value !Constituent minimum value
74+
75+
!Private array of constituent properties (for property interface functions)
76+
type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:)
6977
!----------------------------------------------------------------------------
7078

7179
! check input consistency
@@ -208,35 +216,58 @@ subroutine us_std_atm_set_ic(latvals, lonvals, zint, U, V, T, PS, PHIS_IN, &
208216
zmid2d = 0.5_r8*(zint(:,1:nlev) + zint(:,2:nlev+1))
209217
end if
210218

211-
ncnst = size(m_cnst, 1)
219+
!Get water vapor constituent index:
220+
call const_get_index(wv_stdname, ix_q)
221+
222+
!Determine which "Q" variable index matches water vapor:
223+
m_cnst_ix_q = findloc(m_cnst, ix_q, dim=1)
224+
225+
ncnst = size(m_cnst)
212226
do m = 1, ncnst
213-
if (m_cnst(m) == 1) then
227+
if (m_cnst(m) == m_cnst_ix_q) then
214228
! No water vapor in profile
215229
do k = 1, nlev
216230
where(mask_use)
217231
Q(:,k,m_cnst(m)) = 0.0_r8
218232
end where
219233
end do
220-
!Un-comment once constituents are working in CAMDEN -JN:
221-
#if 0
222234
if(masterproc .and. verbose_use) then
223-
write(iulog,*) ' ', trim(cnst_name(m_cnst(m))), ' initialized by '//subname
224-
end if
225-
else
226-
if (present(zint)) then
227-
call cnst_init_default(m_cnst(m), latvals, lonvals, Q(:,:,m_cnst(m)),&
228-
mask=mask_use, verbose=verbose_use, notfound=.false., z=zmid2d)
229-
else
230-
call cnst_init_default(m_cnst(m), latvals, lonvals, Q(:,:,m_cnst(m)),&
231-
mask=mask_use, verbose=verbose_use, notfound=.false.)
235+
write(iulog,*) ' ', wv_stdname, ' initialized by '//subname
232236
end if
233-
#else
234237
else
235-
!Initialize cloud liquid and rain until constituent routines are enabled:
236-
Q(:,:,m_cnst(m)) = 0.0_r8
237-
#endif
238-
end if
239-
end do
238+
239+
!Extract constituent minimum value:
240+
const_qmin_value = const_qmin(m_cnst(m))
241+
242+
!Initialize constituent to its minimum value:
243+
Q(:,:,m) = real(const_qmin_value, r8)
244+
245+
if (iret /= 0) then
246+
call endrun(errmsg, file=__FILE__, line=__LINE__)
247+
end if
248+
249+
if (const_has_default) then
250+
251+
!If default value exists, then extract default value
252+
!from constituent properties object:
253+
call const_props(m_cnst(m))%default_value(const_default_value, &
254+
iret, &
255+
errmsg)
256+
if (iret /= 0) then
257+
call endrun(errmsg, file=__FILE__, line=__LINE__)
258+
end if
259+
260+
!Set constituent to default value in masked region:
261+
do k=1,nlev
262+
where(mask_use)
263+
Q(:,k,m) = real(const_default_value, r8)
264+
end where
265+
end do
266+
267+
end if !has_default
268+
269+
end if !water vapor
270+
end do !ncnst
240271

241272
if (allocated(zmid2d)) deallocate(zmid2d)
242273

src/dynamics/tests/namelist_definition_analy_ic.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
<type>char*80</type>
99
<category>dyn_test</category>
1010
<group>analytic_ic_nl</group>
11-
<valid_values>none,held_suarez_1994,moist_baroclinic_wave_dcmip2016,dry_baroclinic_wave_dcmip2016,dry_baroclinic_wave_jw2006</valid_values>
11+
<valid_values>
12+
none,held_suarez_1994,moist_baroclinic_wave_dcmip2016,dry_baroclinic_wave_dcmip2016,dry_baroclinic_wave_jw2006,us_standard_atmosphere
13+
</valid_values>
1214
<desc>
1315
Specify the type of analytic initial conditions for an initial run.
1416
held_suarez_1994: Initial conditions specified in Held and Suarez (1994)

0 commit comments

Comments
 (0)