Skip to content

Commit db4b566

Browse files
stacywaltersdavegill
authored andcommitted
Modify source files to implement lightning time controls that work for both a fixed or variable domain time step. (#344)
TYPE: bug fix KEYWORDS: lightning SOURCE: internal DESCRIPTION OF CHANGES: Prior timing controls in the routine lightning_driver would not work properly when adaptive time stepping was enabled. Similar changes were required in the lightning_nox_driver routine. The variable ltngacttime was added to Registry.EM_COMMON to enable proper restarting. LIST OF MODIFIED FILES: M Registry/Registry.EM_COMMON M chem/emissions_driver.F M chem/module_lightning_nox_driver.F M dyn_em/module_after_all_rk_steps.F M dyn_em/solve_em.F M dyn_em/start_em.F M phys/module_diagnostics_driver.F M phys/module_lightning_driver.F TESTS CONDUCTED: WTF reg test has been completed on Cheyenne. All compilations passed and only the em_b_wave run case input.2VN from the PGI compiler failed due to a missing DPLACE file. The code has been tested by Stacy Walters.
1 parent b8b291e commit db4b566

8 files changed

+57
-28
lines changed

Diff for: Registry/Registry.EM_COMMON

+1
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ state integer number_at_same_level - - - - -
421421
state real radtacttime - - - - r "radtacttime" "RADTACTTIME" "LW SW ACTIVATION TIME in s"
422422
state real bldtacttime - - - - r "bldtacttime" "BLDTACTTIME" "PBL ACTIVATION TIME in s"
423423
state real cudtacttime - - - - r "cudtacttime" "CUDTACTTIME" "CPS ACTIVATION TIME in s"
424+
state real ltngacttime - - - - r "ltngacttime" "LTNGACTTIME" "LTNG ACTIVATION TIME in s"
424425
state real power ij misc 1 - irh "Power" "Power production" "W"
425426

426427

Diff for: chem/emissions_driver.F

+1-1
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,7 @@ subroutine emissions_driver(id,ktau,dtstep,DX, &
15461546
! Lightning NO emission
15471547
CALL lightning_nox_driver ( &
15481548
! Frequently used prognostics
1549-
itimestep=ktau, dt=dtstep, dx=dx, dy=dx, &
1549+
curr_secs=curr_secs, dt=dtstep, dx=dx, dy=dx, &
15501550
xlat=xlat, xlon=xlong, xland=xland, ht=ht, &
15511551
t_phy=t_phy, p_phy=p_phy, rho=rho_phy, u=u_phy, v=v_phy, w=vvel, &
15521552
z=z, moist=moist, &

Diff for: chem/module_lightning_nox_driver.F

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ MODULE module_lightning_nox_driver
1717

1818
SUBROUTINE lightning_nox_driver ( &
1919
! Frequently used prognostics
20-
itimestep, dt, dx, dy, &
20+
curr_secs, dt, dx, dy, &
2121
xlat, xlon, xland, ht, &
2222
t_phy, p_phy, rho, u, v, w, &
2323
z, moist, &
@@ -56,7 +56,7 @@ SUBROUTINE lightning_nox_driver ( &
5656
!-----------------------------------------------------------------
5757

5858
! Frequently used prognostics
59-
INTEGER, INTENT(IN ) :: itimestep
59+
REAL(8), INTENT(IN ) :: curr_secs
6060
REAL, INTENT(IN ) :: dt, dx, dy
6161

6262
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(IN ) :: xlat, xlon, xland, ht
@@ -97,11 +97,9 @@ SUBROUTINE lightning_nox_driver ( &
9797

9898
!-----------------------------------------------------------------
9999

100-
IF ( lightning_option .eq. 0 .or. lnox_opt .eq. 0) RETURN
100+
IF (lightning_option .eq. 0 .or. lnox_opt .eq. 0) RETURN
101101

102-
IF ( itimestep * dt .lt. lightning_start_seconds ) RETURN
103-
104-
! IF ( MOD((itimestep * dt - lightning_start_seconds), lightning_dt ) .ne. 0 ) RETURN
102+
IF ((curr_secs+REAL(dt,8)) .lt. REAL(lightning_start_seconds,8)) RETURN
105103

106104
IF ( N_IC .eq. 0. .and. N_CG .eq. 0. ) RETURN
107105
!-----------------------------------------------------------------

Diff for: dyn_em/module_after_all_rk_steps.F

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SUBROUTINE after_all_rk_steps ( grid, config_flags, &
1515
moist, chem, tracer, scalar, &
1616
th_phy, pi_phy, p_phy, rho_phy, &
1717
p8w, t8w, dz8w, &
18-
curr_secs2, &
18+
curr_secs, curr_secs2, &
1919
diag_flag, &
2020
ids, ide, jds, jde, kds, kde, &
2121
ims, ime, jms, jme, kms, kme, &
@@ -99,6 +99,7 @@ SUBROUTINE after_all_rk_steps ( grid, config_flags, &
9999

100100
! Time (s) since the beginning of the restart.
101101

102+
REAL(8) :: curr_secs
102103
REAL :: curr_secs2
103104

104105
! Is this to be a history output time? If so, compute the diagnostics.
@@ -152,7 +153,7 @@ SUBROUTINE after_all_rk_steps ( grid, config_flags, &
152153
moist, chem, tracer, scalar, &
153154
th_phy, pi_phy, p_phy, rho_phy, &
154155
p8w, t8w, dz8w, &
155-
curr_secs2, &
156+
curr_secs, curr_secs2, &
156157
diag_flag, &
157158
ids, ide, jds, jde, kds, kde, &
158159
ims, ime, jms, jme, kms, kme, &

Diff for: dyn_em/solve_em.F

+1-1
Original file line numberDiff line numberDiff line change
@@ -4601,7 +4601,7 @@ SUBROUTINE solve_em ( grid , config_flags &
46014601
moist, chem, tracer, scalar, &
46024602
th_phy, pi_phy, p_phy, rho_phy, &
46034603
p8w, t8w, dz8w, &
4604-
curr_secs2, &
4604+
REAL(curr_secs,8), curr_secs2, &
46054605
diag_flag, &
46064606
ids, ide, jds, jde, kds, kde, &
46074607
ims, ime, jms, jme, kms, kme, &

Diff for: dyn_em/start_em.F

+2-1
Original file line numberDiff line numberDiff line change
@@ -1309,13 +1309,14 @@ SUBROUTINE start_domain_em ( grid, allowed_to_read &
13091309
#endif
13101310
13111311
call wrf_debug(100,'start_em: calling lightning_init')
1312-
CALL lightning_init ( itimestep=grid%itimestep, restart=grid%restart, dt=grid%dt, dx=grid%dx &
1312+
CALL lightning_init ( id=grid%id, itimestep=grid%itimestep, restart=grid%restart, dt=grid%dt, dx=grid%dx &
13131313
! Namelist control options
13141314
,cu_physics=config_flags%cu_physics,mp_physics=config_flags%mp_physics &
13151315
,do_radar_ref=config_flags%do_radar_ref &
13161316
,lightning_option=config_flags%lightning_option &
13171317
,lightning_dt=config_flags%lightning_dt &
13181318
,lightning_start_seconds=config_flags%lightning_start_seconds &
1319+
,ltngacttime=grid%ltngacttime &
13191320
,iccg_prescribed_num=config_flags%iccg_prescribed_num &
13201321
,iccg_prescribed_den=config_flags%iccg_prescribed_den &
13211322
,cellcount_method=config_flags%cellcount_method &

Diff for: phys/module_diagnostics_driver.F

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SUBROUTINE diagnostics_driver ( grid, config_flags, &
1818
moist, chem, tracer, scalar, &
1919
th_phy, pi_phy, p_phy, rho_phy, &
2020
p8w, t8w, dz8w, &
21-
curr_secs2, &
21+
curr_secs, curr_secs2, &
2222
diag_flag, &
2323
ids, ide, jds, jde, kds, kde, &
2424
ims, ime, jms, jme, kms, kme, &
@@ -114,8 +114,9 @@ SUBROUTINE diagnostics_driver ( grid, config_flags, &
114114
p8w , &
115115
t8w
116116

117-
! Time (s) since the beginning of the restart.
117+
! Time (s) since the beginning of the simulation, restart.
118118

119+
REAL(8) :: curr_secs
119120
REAL :: curr_secs2
120121

121122
! Is this to be a history output time? If so, compute the diagnostics.
@@ -190,7 +191,7 @@ SUBROUTINE diagnostics_driver ( grid, config_flags, &
190191
CALL wrf_debug ( 100 , '--> CALL DIAGNOSTICS PACKAGE: LIGHTNING_DRIVER' )
191192
CALL lightning_driver ( &
192193
! Frequently used prognostics
193-
grid%itimestep, grid%dt, grid%dx, grid%dy, &
194+
curr_secs, grid%dt, grid%dx, grid%dy, &
194195
grid%xlat, grid%xlong, grid%xland, grid%ht, &
195196
grid%t_phy, p_phy, grid%rho, &
196197
grid%u_phy, grid%v_phy, grid%w_2, &
@@ -203,6 +204,7 @@ SUBROUTINE diagnostics_driver ( grid, config_flags, &
203204
config_flags%lightning_option, &
204205
config_flags%lightning_dt, &
205206
config_flags%lightning_start_seconds, &
207+
grid%ltngacttime, &
206208
config_flags%flashrate_factor, &
207209
! IC:CG namelist settings
208210
config_flags%iccg_method, &

Diff for: phys/module_lightning_driver.F

+40-14
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ MODULE module_lightning_driver
2626
!**********************************************************************
2727

2828
SUBROUTINE lightning_init ( &
29-
itimestep, restart, dt, dx &
29+
id, itimestep, restart, dt, dx &
3030
! Namelist control options
3131
,cu_physics,mp_physics,do_radar_ref &
3232
,lightning_option, lightning_dt &
3333
,lightning_start_seconds &
34+
,ltngacttime &
3435
,iccg_prescribed_num, iccg_prescribed_den &
3536
,cellcount_method &
3637
! Order dependent args for domain, mem, and tile dims
@@ -52,13 +53,13 @@ SUBROUTINE lightning_init ( &
5253
IMPLICIT NONE
5354
!-----------------------------------------------------------------
5455

56+
INTEGER, INTENT(IN) :: id
5557
INTEGER, INTENT(IN) :: itimestep
5658
LOGICAL, INTENT(IN) :: restart
5759
REAL, INTENT(IN) :: dt,dx
5860
INTEGER, INTENT(IN) :: cu_physics,mp_physics,do_radar_ref,lightning_option
59-
!REAL, INTENT(IN) :: lightning_dt, lightning_start_seconds
60-
REAL, INTENT(IN) :: lightning_start_seconds
61-
REAL, INTENT(INOUT) :: lightning_dt
61+
REAL, INTENT(IN) :: lightning_dt, lightning_start_seconds
62+
REAL, INTENT(INOUT) :: ltngacttime
6263
REAL, INTENT(IN) :: iccg_prescribed_num, iccg_prescribed_den
6364
INTEGER, INTENT(INOUT) :: cellcount_method
6465
INTEGER , INTENT(IN) :: ids, ide, jds, jde, kds, kde, &
@@ -82,15 +83,23 @@ SUBROUTINE lightning_init ( &
8283
!-----------------------------------------------------------------
8384

8485
!-- do not reset unless it is the first timestep or lightning_option is on
85-
IF (itimestep .gt. 0 .or. lightning_option .eq. 0) return
86+
IF (lightning_option .eq. 0) THEN
87+
return
88+
ENDIF
89+
90+
!-- check to see if lightning_dt is less than zero
91+
IF ( lightning_dt <= 0. ) THEN
92+
CALL nl_set_lightning_dt( id, dt )
93+
ENDIF
8694

87-
!-- check to see if lightning_dt is a proper multiple of dt
88-
IF ( lightning_dt == 0. ) THEN
89-
lightning_dt = dt
90-
ELSEIF ( ABS(1.-(1./NINT(lightning_dt/dt)) * (lightning_dt/dt)) .GT. 0.001 ) THEN
91-
CALL wrf_error_fatal (' lightning_init: lightning_dt needs to be a multiple of model time step dt')
95+
!-- restarting? Code after this point is only executed on the very
96+
! first time step of the simulation
97+
IF (itimestep .gt. 0 ) THEN
98+
return
9299
ENDIF
93100

101+
ltngacttime = lightning_start_seconds
102+
94103
!-- check to see if the prescribed IC:CG ratio is valid (0/0 and -1 are not allowed)
95104
IF (iccg_prescribed_den .eq. 0. .and. iccg_prescribed_num .eq. 0.) THEN
96105
CALL wrf_error_fatal (' lightning_init: iccg_prescribed cannot be 0.0/0.0')
@@ -198,7 +207,7 @@ END SUBROUTINE lightning_init
198207

199208
SUBROUTINE lightning_driver ( &
200209
! Frequently used prognostics
201-
itimestep, dt, dx, dy, &
210+
curr_secs, dt, dx, dy, &
202211
xlat, xlon, xland, ht, &
203212
t_phy, p_phy, rho, u, v, w, &
204213
th_phy, pi_phy,dz8w, &
@@ -211,6 +220,7 @@ SUBROUTINE lightning_driver ( &
211220
lightning_option, &
212221
lightning_dt, &
213222
lightning_start_seconds, &
223+
ltngacttime, &
214224
flashrate_factor, &
215225
! IC:CG namelist settings
216226
iccg_method, &
@@ -256,7 +266,7 @@ SUBROUTINE lightning_driver ( &
256266
!-----------------------------------------------------------------
257267

258268
! Frequently used prognostics
259-
INTEGER, INTENT(IN ) :: itimestep
269+
REAL(8), INTENT(IN ) :: curr_secs
260270
REAL, INTENT(IN ) :: dt, dx, dy
261271

262272
REAL, DIMENSION( ims:ime, jms:jme ), INTENT(IN ) :: xlat, xlon, xland, ht
@@ -274,6 +284,7 @@ SUBROUTINE lightning_driver ( &
274284
! Mandatory namelist inputs
275285
INTEGER, INTENT(IN ) :: lightning_option
276286
REAL, INTENT(IN ) :: lightning_dt, lightning_start_seconds, flashrate_factor
287+
REAL, INTENT(INOUT) :: ltngacttime
277288

278289
! IC:CG namelist settings
279290
INTEGER, INTENT(IN ) :: iccg_method
@@ -295,8 +306,11 @@ SUBROUTINE lightning_driver ( &
295306

296307

297308
! Local variables
309+
REAL(8) :: LtngActivationTime
310+
REAL(8) :: nextTime
298311
REAL, DIMENSION( ims:ime, jms:jme ) :: total_flashrate
299312
CHARACTER (LEN=80) :: message
313+
LOGICAL :: do_ltng
300314

301315
REAL, PARAMETER :: reflthreshold = 20. ! reflectivity threshold for CRM schemes
302316
REAL, DIMENSION( kms:kme ) :: cellcount
@@ -305,9 +319,13 @@ SUBROUTINE lightning_driver ( &
305319

306320
IF ( lightning_option .eq. 0 ) RETURN
307321

308-
IF ( itimestep * dt .lt. lightning_start_seconds ) RETURN
322+
nextTime = curr_secs + REAL(dt,8)
323+
LtngActivationTime = REAL(ltngacttime,8)
324+
do_ltng = LtngActivationTime >= curr_secs .and. LtngActivationTime <= nextTime
309325

310-
IF ( MOD((itimestep * dt - lightning_start_seconds), lightning_dt ) .ne. 0 ) RETURN
326+
IF( .not. do_ltng ) THEN
327+
RETURN
328+
ENDIF
311329

312330
!-----------------------------------------------------------------
313331
! This driver performs several steps in order to produce lightning
@@ -565,6 +583,14 @@ SUBROUTINE lightning_driver ( &
565583

566584
ic_flashcount(its:ite,jts:jte) = ic_flashcount(its:ite,jts:jte) + ic_flashrate(its:ite,jts:jte) * lightning_dt
567585
cg_flashcount(its:ite,jts:jte) = cg_flashcount(its:ite,jts:jte) + cg_flashrate(its:ite,jts:jte) * lightning_dt
586+
587+
do
588+
if( REAL(ltngacttime,8) <= nextTime ) then
589+
ltngacttime = ltngacttime + lightning_dt
590+
else
591+
exit
592+
endif
593+
enddo
568594

569595
!-----------------------------------------------------------------
570596

0 commit comments

Comments
 (0)