Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve time-stepping issue in ELMO when used within WRF-CMAQ and MPAS-CMAQ #181

Merged
merged 1 commit into from
Dec 2, 2022
Merged
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
2 changes: 1 addition & 1 deletion CCTM/src/driver/ELMO_DATA.F
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ MODULE ELMO_DATA
Logical, Parameter, Private :: F = .false.

LOGICAL, SAVE :: L_ELMO
INTEGER, SAVE :: ELMO_AVRG_STEP = 0
REAL, SAVE :: ELMO_NSTEP = 0.
INTEGER, SAVE :: NLAY_ELMO_INST
INTEGER, SAVE :: NLAY_ELMO_AVRG

Expand Down
56 changes: 31 additions & 25 deletions CCTM/src/driver/ELMO_PROC.F
Original file line number Diff line number Diff line change
Expand Up @@ -3053,7 +3053,7 @@ SUBROUTINE LOAD_ELMO( C,R,L,CONC,WRITE_STEP, INIT_STEP, INIT_TIME )
END SUBROUTINE LOAD_ELMO

!-------------------------------------------------------------------------
SUBROUTINE ELMO_DRIVER( CGRID, JDATE, JTIME, TSTEP, INIT_TIME, INIT_STEP )
SUBROUTINE ELMO_DRIVER( CGRID, JDATE, JTIME, TSTEP, INIT_TIME )
! This subroutine maps the PM diagnostic variables that the user has
! requested to the entries in the ELMO_DATA table.
!-------------------------------------------------------------------------
Expand All @@ -3071,6 +3071,8 @@ SUBROUTINE ELMO_DRIVER( CGRID, JDATE, JTIME, TSTEP, INIT_TIME, INIT_STEP )
& CFRAC, DZ, PV, ZH
use centralized_io_module, only : interpolate_var, pv_avail
use RUNTIME_VARS
Use phot_mod, Only: init_phot_shared

#ifdef sens
USE DDM3D_DEFN, ONLY : SENGRID
#endif
Expand All @@ -3084,7 +3086,7 @@ SUBROUTINE ELMO_DRIVER( CGRID, JDATE, JTIME, TSTEP, INIT_TIME, INIT_STEP )
INTEGER, INTENT( IN ) :: TSTEP(3)
LOGICAL, INTENT( IN ) :: INIT_TIME ! Is this the first time step
! of the simulation
LOGICAL, INTENT( IN ) :: INIT_STEP ! Is the time step beginning
LOGICAL :: INIT_STEP ! Is the time step beginning

! Variable to set time step for writing visibility file
INTEGER, SAVE :: WSTEP = 0 ! local write counter
Expand Down Expand Up @@ -3118,7 +3120,7 @@ SUBROUTINE ELMO_DRIVER( CGRID, JDATE, JTIME, TSTEP, INIT_TIME, INIT_STEP )
IF ( FIRSTIME ) THEN
FIRSTIME = .FALSE.
! Initialize Number of Steps Used for Calculating Average
ELMO_AVRG_STEP = 0
ELMO_NSTEP = 0.

ALLOCATE( PRES( NCOLS, NROWS, NLAYS),
& TA( NCOLS, NROWS, NLAYS ),
Expand All @@ -3133,15 +3135,16 @@ SUBROUTINE ELMO_DRIVER( CGRID, JDATE, JTIME, TSTEP, INIT_TIME, INIT_STEP )

! Determine if this is a write step
WRITE_STEP = .FALSE.

IF ( INIT_STEP ) THEN
INIT_STEP = .FALSE.
IF ( ELMO_NSTEP .LT. 1.0 ) THEN
WSTEP = 0
INIT_STEP = .TRUE.
ELSE
ELMO_AVRG_STEP = ELMO_AVRG_STEP + 1
WSTEP = WSTEP + TIME2SEC( TSTEP( 2 ) )
IF ( WSTEP .GE. TIME2SEC( TSTEP( 1 ) ) )
& WRITE_STEP = .TRUE.
END IF
ELMO_NSTEP = ELMO_NSTEP + 1.0

! Get Meteorological Variables

Expand Down Expand Up @@ -3178,6 +3181,7 @@ SUBROUTINE ELMO_DRIVER( CGRID, JDATE, JTIME, TSTEP, INIT_TIME, INIT_STEP )
call interpolate_var ('ZH', jdate, jtime, ZHS)

! Calculate Heterogeneous Chemistry Rates
CALL INIT_PHOT_SHARED()
CALL HETCHEM_RATES( TA, PRES, QV, CGRID, DENS )

! Process PM Diagnostics for Base Model
Expand Down Expand Up @@ -3403,25 +3407,27 @@ SUBROUTINE WRITE_ELMO ( JDATE, JTIME, TSTEP, INIT_TIME )
END IF

C *** Write data to the average aerosol diagnostic file.
IF ( AVRG_ACTIVE .AND. .NOT.INIT_TIME ) THEN
IF ( .NOT. END_TIME ) THEN ! ending time timestamp
CALL NEXTIME ( MDATE, MTIME, -TSTEP(1) )
END IF

IF ( .NOT. WRITE3( CTM_AELMO_1,
& ALLVAR3, MDATE, MTIME,
& ELMO_AVRG(:,:,:,:) / 2.0 /
& ELMO_AVRG_STEP ) ) THEN
XMSG = 'Could not write ' // CTM_AELMO_1 // ' file'
CALL M3EXIT ( PNAME, MDATE, MTIME, XMSG, XSTAT1 )
END IF

WRITE( LOGDEV, '( /5X, 3( A, :, 1X ), I8, ":", I6.6 )' )
& 'Timestep written to', CTM_AELMO_1,
& 'for date and time', MDATE, MTIME

ELMO_AVRG_STEP = 0

IF ( .NOT.INIT_TIME ) THEN
IF ( AVRG_ACTIVE ) THEN
IF ( .NOT. END_TIME ) THEN ! ending time timestamp
CALL NEXTIME ( MDATE, MTIME, -TSTEP(1) )
END IF

IF ( .NOT. WRITE3( CTM_AELMO_1,
& ALLVAR3, MDATE, MTIME,
& ELMO_AVRG(:,:,:,:) / 2.0 /
& (ELMO_NSTEP-1.0) ) ) THEN
XMSG = 'Could not write ' // CTM_AELMO_1 // ' file'
CALL M3EXIT ( PNAME, MDATE, MTIME, XMSG, XSTAT1 )
END IF

WRITE( LOGDEV, '( /5X, 3( A, :, 1X ), I8, ":", I6.6 )' )
& 'Timestep written to', CTM_AELMO_1,
& 'for date and time', MDATE, MTIME


END IF
ELMO_NSTEP = 0.
END IF
RETURN

Expand Down
13 changes: 5 additions & 8 deletions CCTM/src/driver/driver.F
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ SUBROUTINE CMAQ_DRIVER ( MODEL_STDATE, MODEL_STTIME, MODEL_TSTEP,
USE RXNS_DATA ! chemical mechanism data
USE BUDGET_DEFN
USE AERO_DATA
USE ELMO_DATA, ONLY : L_ELMO
USE ELMO_DATA, ONLY : L_ELMO, ELMO_NSTEP
USE ELMO_PROC, ONLY : ELMO_DRIVER, WRITE_ELMO, MAP_ELMO
#ifdef mpas
USE CGRID_SPCS ! CGRID mechanism species
Expand Down Expand Up @@ -707,15 +707,13 @@ END SUBROUTINE UNLOAD_CGRID

! Calculate all ELMO variables for both Instantaneous and
! Average parameters
CALL ELMO_DRIVER( CGRID, JDATE, JTIME, TSTEP,
& INIT_TIME=.TRUE., INIT_STEP=.TRUE. )
CALL ELMO_DRIVER( CGRID, JDATE, JTIME, TSTEP, INIT_TIME=.TRUE.)
! Print Instantaneous Values at first time step
CALL WRITE_ELMO( JDATE, JTIME, TSTEP, INIT_TIME=.TRUE. )

ELSE
ELSE IF ( ELMO_NSTEP .LT. 1.0 ) THEN
! Calculate all ELMO Variables for averaging but do not output them
CALL ELMO_DRIVER( CGRID, JDATE, JTIME, TSTEP,
& INIT_TIME=.FALSE., INIT_STEP=.TRUE. )
CALL ELMO_DRIVER( CGRID, JDATE, JTIME, TSTEP, INIT_TIME=.FALSE. )
END IF
END IF

Expand Down Expand Up @@ -773,8 +771,7 @@ END SUBROUTINE UNLOAD_CGRID

#endif
! OUTPUT DIAGNOSTIC INFORMATION
IF ( L_ELMO ) CALL ELMO_DRIVER( CGRID, JDATE, JTIME, TSTEP,
& INIT_TIME=.FALSE., INIT_STEP=.FALSE. )
IF ( L_ELMO ) CALL ELMO_DRIVER( CGRID, JDATE, JTIME, TSTEP, INIT_TIME=.FALSE. )

END DO

Expand Down
4 changes: 2 additions & 2 deletions CCTM/src/init/initscen.F
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ SUBROUTINE INITSCEN ( CGRID, TSTEP)
USE HGRD_DEFN ! horizontal domain specifications
USE CGRID_SPCS ! CGRID mechanism species
USE UTILIO_DEFN
USE ELMO_DATA, ONLY : L_ELMO, ELMO_AVRG_STEP
USE ELMO_DATA, ONLY : L_ELMO, ELMO_NSTEP
USE ELMO_PROC, ONLY : OPEN_ELMO
#ifdef parallel
USE SE_MODULES ! stenex (using SE_UTIL_MODULE)
Expand Down Expand Up @@ -233,7 +233,7 @@ END SUBROUTINE LOAD_SENGRID
C *** Open the aerosol parameters file (diameters and standard deviations).
IF ( L_ELMO .AND. IO_PE_INCLUSIVE ) THEN
CALL OPEN_ELMO ( STDATE, STTIME, TSTEP( 1 ) )
ELMO_AVRG_STEP = 0
ELMO_NSTEP = 0.0
END IF

IF ( .NOT. OPEN3( CTM_CONC_1, FSRDWR3, PNAME ) ) THEN
Expand Down