Homework on CMAQ

[ Home | Homework | ]


Homework Assignments


2024
Details


25 Mar

Intro to the CMAQ model (an Eulerian model).  Overview of smog chemistry. Discussion of chemical-reaction eqs. used in CMAQ.  Assignment of HW7 on smog, but using simplified chemistry.  

If time, discussion of the PPM method for advection.  Assignment of CMAQ Tech Manual discussions (to be presented on Wed). 

Hopefully every student has used the poll in Piazza to vote for the CMAQ topics that they would like to present.

If time, start a few of the student presentations on the CMAQ Tech Manual. (see info below for 27 Mar., and also see more details in Piazza.

Bring your laptop. Make sure it is fully charged.
.
25 Mar
# ATSC 595D Atmospheric Dispersion Modeling - HW7
# Homework exercise on smog reactions. Simplified from CMAQ.
# R. Stull - 5 Aug 2018, updated 26 Nov 2021, 16 Mar 2024.

# Adopted from Chapter 8 (section 8.2 Tropospheric Ozone) of free online textbook:
# "Atmospheric Chemistry" by István Lagzi, Róbert Mészáros, Györgyi Gelybó, Ádám Leelőssy
# "Copyright © 2013 Eötvös Loránd University, Budapest, Hungary.
#   This book is freely available for research and educational purposes."
# https://ttk.elte.hu/dstore/document/848/book.pdf
# (Accessed on 26 Nov 2021, 20 Mar 2024.)

# ========= Background Info ============

# Scenario: Simple example of ozone production from carbon monoxide and sunlight.
# Need to forecast concentrations of 7 chemicals that react with each other:
#   OH = hydroxyl radical
#   HO2 = hydroperoxly radical
#   NO = nitric oxide
#   NO2 = nitrogen dioxide
#   CO = carbon monoxide (a primary pollutant)
#   O1D = excited atomic oxygen (higher energy; more reactive)
#   O3 = ozone (as a secondary pollutant)

# Other 4 chemicals that are involved, but for which we don't need to forecast
#   O2 = molecular oxygen  (because ambient concentration is so large)
#   CO2 = carbon dioxide  (secondary product we don't care about here)
#   H2O = water vapour  (because ambient concentration is so large)
#   M = any non-reactive 3rd molecule, needed to remove energy from a reaction

# The 6 chemical reactions {as identified with CMAQ CB6 eq numbers}:
# {01'}  NO2 + h_nu     -> NO + O3
# {03}   O3 + NO        -> (O2) + NO2
# {09}   O3 + h_nu      -> (O2) + O1D
# {11}   O1D + H2O      -> 2 OH
# {25}   HO2 + NO       -> OH + NO2
# {123}  OH +CO +(O2)   -> HO2 + (CO2)
# where the items in parenthesis ( ) are items we can ignore in the rate eqs.
#(Note: {01'} is the combination of CB6 reactions {01} and {02}. )

# By neglecting the chemicals in ( ), this has the effect of reducing the
# order of the reaction. Also, we will assume h·nu is a known constant.
# The following are essentially 1st order reactions: {01', 09}.
# The following are essentially 2nd order reactions: {03, 11, 25, 123}.

# Let [ ] be the concentration of a chemical in units of molecules/cm^3.
# Rate equations predict the change in concentration [ ] of chemicals
# participating in a chemical reaction.  For example, consider:
#   1st order photolysis of A -> C.     Rate eq is:  d[C]/dt = j*[A]
#   2nd order reaction of A + B -> C.   Rate eq is:  d[C]/dt = k*[A]*[B]
# where
#   "photolysis rate constant" j has units of (s^-1)
#   "reaction rate constant"   k has units of ( (s * molecules/cm^3)^-1 )
# Although j varies with solar elevation, cloudiness, etc.,
# we will assume j = constant for simplicity in this exercise.

# For example, for reaction {25}, you have 1 production/loss term R
# and 4 rate eqs:
# {25.0}   Define R25 = k25*[HO2]*[NO]
# {25.1}   d[OH]/dt = R25
# {25.2}   d[NO2]/dt = R25
# {25.3}   d[HO2]/dt = -R25
# {25.4}   d[NO]/dt = -R25
# Note the minus sign for the last 2 eqs, which describe the loss of the
# reactants from the left side of reaction {25}.

# We can change each rate eq to a forward finite difference.  For example:
# For example, rate eq {25.1}    d[OH]/dt = R25  becomes
#
# [OH](new) = [OH](old) + delt * R25(old)
#
# where R25(old) = k25*[HO2]*[NO] (old) , and where delt is the timestep.
# Thus, each of the {25.x} eqs has a corresponding finite-difference form.


# ============== Your homework assignment ===========
# CAUTION: The notation both above and below use meta-code to specify
# physical processes and exercises.  The syntax might be incorrect
# for your computer language, so you will need to fix it.

#    For exercises A & B, write or type your answer on a piece
# of paper to submit.  (You don't need to use an eq. editor for this.)

# A(1). For each chemical reaction {} listed above, how many eqs apply,
#       and what is the resulting total number of equations?
#
#   For example,

#      Reaction {25} has 4 rate eqs + 1 R definition = 5 eqs.
#   Hint: don't write rate eqs to forecast any chemical in parenthesis (),
#   or for any chemical that we are considering to be constant (O2, H2O).
#
# A(2). For each one of the 7 chemicals that we want to forecast,

#   how many R production/loss terms apply?
#   For example,
#     NO has 3  R terms: 1 gain in {01'} and 2 losses in {03} & {25}.


# B. Write all of the reaction eqs (similar to {25.0 to 25.4} shown above).
# But don't include reaction eqs for items in parenthesis ( ), or for
# any variable we assume is constant.


# C. In your favorite programming language, write into your computer
# program the finite difference form of the forecast eqs for each
# of the 7 chemicals of interest.
#    (1) CAUTION: During any one timestep, be sure to use all current
# concentrations to calculate ALL the R terms for all rate eqs.
#    (2) Note that some chemicals will have several R terms. Only
# after finding ALL the R terms will you use them in the
# forward difference with +sign for gains and -signs for losses.
# For example (using c_ to represent concentrations from now on):
#
# c_O3 = c_O3 + delt * [R01' - R03 - R09]
#
#   (3) CAUTION: truncate any negative concentrations to zero.


# D. Iterate your eqs forward in time on the computer, using the
# initial conditions IC and specifications given below.
#   Hint: use the IC values in all your finite difference eqs to step
# forward in time one timestep "delt" to get new concentration values
# of all 7 chemicals.
#    Then, once you have NEW concentration values for all 7 chemicals,
# (truncated to be non-negative)
# copy them into your array of OLD concentrations, use them to step
# forward another time step.  Repeat for each time step.
#    End at the elapsed time specified below.
# Hint: Don't save every timestep for plotting and other calculations. 
# Instead, save concentration values periodically (as specified)
# for all 7 chemicals, for the next 2 exercises.


# E(a). Using your output saved from D, convert the concentrations
# of the following 4 variables from c (molecules/cm^3) to mixing ratio
#  q (ppm) using the following approximate formula:
#
#         q(ppm) = c(molecules/cm^3) * (4.0e-14)
#
# E(b). Plot on the same one graph the following 4 concentration
# curves in units of ppm:  ppm_CO, ppm_NO, ppm_NO2, ppm_O3
# versus time in hours.  (Plot them only at intervals as given below
# in the specs. (Hint, since you saved values only at specified
# intervals, then these are the only values you need to plot.)


# F. Discuss the significance of your results from E.

# Please submit a printed copy of your results and your code,
# or upload a pdf of your code and handwritten answers to Canvas .


# Note: CMAQ actually keeps track of over 200 chemical reactions,
#  resulting in over 1000 rate equations. We looked at only 6
#  of those reactions in this simplified exercise.


# ======== Specifications for your HW =========

# Rate constants for each reaction (slightly modified from cb6 rates for this exercise)
j01 = 1.0e-3     # (units 1/s)                      for {01'}  NO2 + h·nu   -> NO + O3
k03 = 1.73e-15   # (units (s · molecules/cm^3)^-1 ) for {03}   O3 + NO      -> (O2) + NO2
j09 = 1.0e-6     # (units 1/s)                      for {09}   O3 + h·nu    -> (O2) + O1D
k11 = 2.14e-10   # (units (s · molecules/cm^3)^-1 ) for {11}   O1D + H2O    -> 2 OH
k25 = 8.54e-12   # (units (s · molecules/cm^3)^-1 ) for {25}   HO2 + NO     -> OH + NO2
k123 = 2.28e-14  # (units (s · molecules/cm^3)^-1 ) for {123}  OH +CO +(O2) -> HO2 + (CO2)

# Time step info
delt_s = 0.0001     # time step (s) for your iterations
tend_h = 2.0        # duration of forecast (hours)
tsave_m = 2.0       # how often (minutes) to save results to plot

# Initial concentrations.
c_CO = 2.5e12     # molecules / cm^3
c_HO2 = 0.0       # molecules / cm^3
c_NO = 1.25e12    # molecules / cm^3
c_NO2 = 1.25e11   # molecules / cm^3
c_O1D = 0.0       # molecules / cm^3
c_O3 = 0.0        # molecules / cm^3
c_OH = 0.0        # molecules / cm^3

# Assume the following value is constant.
# (you don't need to forecast it, but you need to use it on the left side of the eqs)
c_H2O = 2.5e15    # molecules / cm^3  which is 0.01% of the air at sea level


# ====== End of assignment.  Good Luck. =========





Write this in your favorite computer language. 
Turn in printed copies of your output graphs and your code.

27 Mar Each student gives a 10 minute presentation to the class on one of the topics listed below, based on the info in the CMAQ overview website  https://www.epa.gov/cmaq/overview-science-processes-cmaq and on links it has to associated technical details. 
  1. Numerics, Grids, Chemical Solvers (1 person)
  2. WRF-CMAQ and MPAS-CMAQ (1 person)
  3. Boundary Layer Processes & Turbulent Diffusion (1 person)
  4. Emission Processes (anthropogenic, biogenic, wildfire, windblown dust, sea spray) (2 people)
  5. Plume-in-Grid (1 person)
  6. Dry Deposition (2 people)
  7. Clouds, Wet Deposition, Bi-directional exchange (1 person)
  8. Radiation and photolysis (1 person)
  9. Chemical mechanisms (gas, aerosols, multiphase) (3 people)

29 Mar - 1 Apr

HOLIDAYS

.
.
3 Apr (due by end of term)

# ATSC 595D Atmospheric Dispersion Modeling -
# Homework exercise on 1-D advection, demonstrating PPM method from CMAQ,
# and comparing it to two other advections schemes: forward in time; and Runge-Kutta.
# PPM is Piecewise Parabolic Method.  For details, see:
# Chapter 7 of the CMAQ Science Document:
#      https://www.cmascenter.org/cmaq/science_documentation/pdf/ch07.pdf
# and the journal paper by Colella and Woodward, 1984, J. Computational Physics,
#      vol 54, pages174-201.
# But the best documentation is the actual fortran code for the
#      horizontal advection subroutine "hadv" from
#      https://github.com/USEPA/CMAQ/archive/5.2.1.zip and look in this path:
#      CCTM/src/hadv/yamo/hppm.F .  This version was updated on March 2018.
#      You can find a link to this fortran code at the end of this assignment.
# R. Stull - 18 Aug 2018, 24 Mar 2024


# In this HW, a 1-D pollutant puff being advected in the x-direction by a constant
# wind u.  The linear advection eq. is ∂c/∂t = - u ∂c/∂c .
# The three schemes you will compare are :
#   (a) FTBS - Forward in time, Backward in space;
#   (b) RK3 - Runga-Kutte 3rd order (WRF-ARW version) in time, Centered in space; and
#   (c) PPM - Piecewise Parabolic Method (from Stull's R code, adapted from the original CMAQ fortran code).
#          Hint: for FTBS & RK3, see Stull's brief review of numerical methods for advection .
#          Hint: for PPM, see Stull's R code fragment, near the end of this asssignment


# Create the grid and initial conditions
imax = 1000             # number of grid points in x-direction
delx = 100.             # horizontal grid spacing (m)
delt = 10.              # time increment (s)
u = 5.                  # horizontal wind speed (m/s) is constant for this exercise

# 1) Calculate and display the Courant number (Cr = u * delt / delx) .  You can display it in the
# graph in the question (3) if you would like. Cr is one measure of numerical stability.

# 2) (a) Create initial concentration distribution in the x-direction.
# Assume that these "conc" variables are actually concentration anomalies relative to a large
# constant background state. Thus, it is OK to have negative values of "conc".
conc <- rep(0.0, imax)   # initialize "conc" anomaly to zero relative to the background concentration.
cmax = 10.0             # max initial "conc" (in arbitrary concentration units)
conc[100:150] <- seq(0., cmax, len = 51)    # insert left side of triangle
conc[150:200] <- seq(cmax, 0., len = 51)    # insert right side of triangle
conc[20:40] <- seq(0., -0.5*cmax, len = 21)    # insert left side of triangle
conc[40:60] <- seq(-0.5*cmax, 0., len = 21)    # insert right side of triangle

#   (b) Plot the initial conc distribution on a graph.

# 3) Also, on the same plot, show the ideal exact final solution, as given by
cideal <- rep(0.0, imax)   # initial conc of ideal background is zero
cideal[800:850] <- seq(0., cmax, len = 51)    # insert left side of triangle
cideal[850:900] <- seq(cmax, 0., len = 51)    # insert right side of triangle
cideal[720:740] <- seq(0., -0.5*cmax, len = 21)    # insert left side of triangle
cideal[740:760] <- seq(-0.5*cmax, 0., len = 21)    # insert right side of triangle

# 4) Use "forward in time, backward in space" (FTBS) to advect conc
# for the following number of time steps
nsteps = (imax - 300) / (u * delt / delx)
# and plot the resulting conc on the same graph.

# 5) Repeat steps (2-4) to re-initialize, but plotting on a new graph, and using the WRF-ARW version of
# RK3-in-time, Centered-in-space for the advection.  Use same number of time steps.

# 6) Repeat steps (2-4) to re-initialize, but plotting on a new graph, and using
# CMAQ PPM for the advection.  Use same number of time steps.
# Here is a code fragment in the R language that shows the PPM algorithm for our simplified
#
homework problem.  You can use or modify it to do this PPM exercise.
# [In case you are interested, here is the original CMAQ fortran code for PPM that
# Stull modified to create his version in R.]

# 7) Discuss and compare the results of these three advection schemes.

Write this in your favorite computer language. 
Turn in printed copies of your output graphs and your code.

3 Apr

CMAQ installation, Part 1. Lead by our TA, Tim Chui.  (See instructions on our CMAQ web page, not the HW page.)

Bring your laptop.

8 Apr

CMAQ installation, Part 2. Lead by our TA, Tim Chui. (Save the CMAQ run output to your own laptop.)

HOMEWORK: Use Panoply to display the Ozone output from CMAQ that you produced during class and saved to your own computer. (Here are the Panoply intro slides presented by Tim Chui.)
A. Produce a plot of ozone with the following characteristics:

  • Map Projection: use stereographic map projection
  • Use mouse to zoom to the region having data (command-click on Mac, control-click on Windows)
  • Plot tab (from top of Panoply window) Size Ratio is 100% in both Width and Height, or smaller to fit on your screen.
  • Grid: display lat and lon every 5° (I used dark green color for the grid)
  • Overlays: add coastal and state boundaries
  • Scale: use range of 0 to 0.08, tic label format %0G, tics 8 major 2 minor
  • Scale: color table: Panoply_16.act
  • Labels: Title = "<yourname> CMAQ Output"

This produces a plot similar to mine, but this is NOT what you will turn in. Instead, pick your own favorite color table, and make any other adjustments needed so that the legend color bar works with your color table. Feel free to make other enhancements. You will submit as HW your resulting still image for this assignment.

B. Using the same format that you created from A (easy to do if you kept your Panoply plot open), create an .mp4 movie animation output (see the Panoply file menu), with a frame rate of 1 fps and Content of TSTEP (7 frames). Also submit this animation as your HW. (As an example, here is my ozone animation output.)

 

Bring your laptop

10 Apr

Last Class day 

Catch up and Summary of the Course.

Meanwhile, finish working on your Homework on Advection (FTBS, RK3, PPM).  Write your own code for this in your favorite computer language.



Other Info





[ Home | Homework | ]

http://www.eos.ubc.ca/courses/atsc507/ADM/
Last updated 29 Mar 2024
Copyright © 2018, 2021, 2024 by Roland Stull.