CAMP 1.0.0
Chemistry Across Multiple Phases
rxn_wennberg_no_ro2.F90
Go to the documentation of this file.
1! Copyright (C) 2021 Barcelona Supercomputing Center,
2! University of Illinois at Urbana-Champaign, and
3! National Center for Atmospheric Research
4! SPDX-License-Identifier: MIT
5
6!> \file
7!> The camp_rxn_wennberg_no_ro2 module.
8
9!> \page camp_rxn_wennberg_no_ro2 CAMP: Wennberg NO + RO2 Reaction
10!!
11!! Wennberg NO + RO2 reactions are branched reactions with one branch forming
12!! alkoxy radicals plus \f$\ce{NO2}\f$ and the other forming organic nitrates
13!! \cite Wennberg2018 . The rate constants for each branch are based on an
14!! Arrhenius rate constant and a temperature- and structure-dependent
15!! branching ratio calculated as:
16!!
17!! \f{align}{
18!! k_{nitrate} & = \left(X e^{-Y/T}\right) \left(\frac{A(T, \mbox{[M]}, n)}{A(T, \mbox{[M]}, n) + Z}\right) \\
19!! k_{alkoxy} & = \left(X e^{-Y/T}\right)\left(\frac{Z}{Z + A(T, \mbox{[M]}, n)}\right) \\
20!! A(T, \mbox{[M]}, n) & = \frac{2 \times 10^{-22} e^n \mbox{[M]}}{1 + \frac{2 \times 10^{-22} e^n \mbox{[M]}}{0.43(T/298)^{-8}}} 0.41^{(1+[log( \frac{2 \times 10^{-22} e^n \mbox{[M]}}{0.43(T/298)^{-8}})]^2)^{-1}}
21!! \f}
22!!
23!! where \f$T\f$ is temperature (K), [M] is the number density of air
24!! (molecules \f$\mbox{cm}^{-3}\f$), \f$X\f$ and \f$Y\f$ are Arrhenius
25!! parameters for the overall reaction, \f$n\f$ is the number of heavy atoms
26!! in the \f$\ce{RO2}\f$ reacting species (excluding the peroxy moiety), and
27!! \f$Z\f$ is defined as a function of two parameters (\f$\alpha_0, n\f$):
28!!
29!! \f[
30!! Z( \alpha_0, n) = A(T = 293 \mbox{K}, \mbox{[M]} = 2.45 \times 10^{19} \frac{\mbox{molec}}{\mbox{cm}^3}, n) \frac{(1-\alpha_0)}{\alpha_0}
31!! \f]
32!!
33!! More details can be found in Wennberg et al. (2018) \cite Wennberg2018 .
34!!
35!! Input data for Wennberg NO + RO2 equations has the following format:
36!! \code{.json}
37!! {
38!! "type" : "WENNBERG_NO_RO2",
39!! "X" : 123.45,
40!! "Y" : 1200.0,
41!! "a0" : 1.0e8,
42!! "n" : 6,
43!! "time unit" : "MIN",
44!! "reactants" : {
45!! "spec1" : {},
46!! "spec2" : { "qty" : 2 },
47!! ...
48!! },
49!! "alkoxy products" : {
50!! "spec3" : {},
51!! "spec4" : { "yield" : 0.65 },
52!! ...
53!! },
54!! "nitrate products" : {
55!! "spec5" : {},
56!! "spec6" : { "yield" : 0.32 },
57!! ...
58!! }
59!! }
60!! \endcode
61!! The key-value pairs \b reactants, and both sets of \b products are
62!! required. Reactants without a \b qty value are assumed to appear once in
63!! the reaction equation. Products without a specified \b yield are assumed
64!! to have a \b yield of 1.0.
65!!
66!! When \b X is not included, it is assumed to be 1.0, when \b Y is not
67!! included, it is assumed to be 0.0 K, when \b a0 is not included, it is
68!! assumed to be 1.0, and when \b n is not included, it is assumed to be 0.
69!! The unit for time is assumed to be s, but inclusion of the optional
70!! key-value pair \b time \b unit = \b MIN can be used to indicate a rate
71!! with min as the time unit.
72
73!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
74
75!> The rxn_wennberg_no_ro2_t type and associated functions.
77
80 use camp_constants, only: const
84 use camp_util, only: i_kind, dp, to_string, &
86
87 implicit none
88 private
89
90#define NUM_REACT_ this%condensed_data_int(1)
91#define NUM_ALKOXY_PROD_ this%condensed_data_int(2)
92#define NUM_NITRATE_PROD_ this%condensed_data_int(3)
93#define X_ this%condensed_data_real(1)
94#define Y_ this%condensed_data_real(2)
95#define a0_ this%condensed_data_real(3)
96#define n_ this%condensed_data_real(4)
97#define CONV_ this%condensed_data_real(5)
98#define NUM_INT_PROP_ 3
99#define NUM_REAL_PROP_ 5
100#define NUM_ENV_PARAM_ 2
101#define REACT_(x) this%condensed_data_int(NUM_INT_PROP_ + x)
102#define PROD_(x) this%condensed_data_int(NUM_INT_PROP_ + NUM_REACT_ + x)
103#define DERIV_ID_(x) this%condensed_data_int(NUM_INT_PROP_ + NUM_REACT_ + NUM_ALKOXY_PROD_ + NUM_NITRATE_PROD_ + x)
104#define JAC_ID_(x) this%condensed_data_int(NUM_INT_PROP_ + 2*(NUM_REACT_ + NUM_ALKOXY_PROD_ + NUM_NITRATE_PROD_) + x)
105#define YIELD_(x) this%condensed_data_real(NUM_REAL_PROP_ + x)
106
107 public :: rxn_wennberg_no_ro2_t
108
109 !> Generic test reaction data type
111 contains
112 !> Reaction initialization
113 procedure :: initialize
114 !> Finalize the reaction
115 final :: finalize
116 end type rxn_wennberg_no_ro2_t
117
118 !> Constructor for rxn_wennberg_no_ro2_t
119 interface rxn_wennberg_no_ro2_t
120 procedure :: constructor
121 end interface rxn_wennberg_no_ro2_t
122
123contains
124
125!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
126
127 !> Constructor for Wennberg no_ro2 reaction
128 function constructor() result(new_obj)
129
130 !> A new reaction instance
131 type(rxn_wennberg_no_ro2_t), pointer :: new_obj
132
133 allocate(new_obj)
134 new_obj%rxn_phase = gas_rxn
135
136 end function constructor
137
138!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
139
140 !> Initialize the reaction data, validating component data and loading
141 !! any required information into the condensed data arrays for use during
142 !! solving
143 subroutine initialize(this, chem_spec_data, aero_rep, n_cells)
144
145 !> Reaction data
146 class(rxn_wennberg_no_ro2_t), intent(inout) :: this
147 !> Chemical species data
148 type(chem_spec_data_t), intent(in) :: chem_spec_data
149 !> Aerosol representations
150 type(aero_rep_data_ptr), pointer, intent(in) :: aero_rep(:)
151 !> Number of grid cells being solved simultaneously
152 integer(kind=i_kind), intent(in) :: n_cells
153
154 type(property_t), pointer :: spec_props, reactants, alkoxy_products, &
155 nitrate_products
156 character(len=:), allocatable :: key_name, spec_name, string_val
157 integer(kind=i_kind) :: i_spec, i_qty
158
159 integer(kind=i_kind) :: temp_int
160 real(kind=dp) :: temp_real
161
162 ! Get the species involved
163 if (.not. associated(this%property_set)) call die_msg(573144252, &
164 "Missing property set needed to initialize reaction")
165 key_name = "reactants"
166 call assert_msg(350413096, &
167 this%property_set%get_property_t(key_name, reactants), &
168 "Wennberg NO + RO2 reaction is missing reactants")
169 key_name = "alkoxy products"
170 call assert_msg(575049786, &
171 this%property_set%get_property_t(key_name, alkoxy_products), &
172 "Wennberg NO + RO2 reaction is missing alkoxy products")
173 key_name = "nitrate products"
174 call assert_msg(794422169, &
175 this%property_set%get_property_t(key_name, nitrate_products), &
176 "Wennberg NO + RO2 reaction is missing nitrate products")
177
178 ! Count the number of reactants (including those with a qty specified)
179 call reactants%iter_reset()
180 i_spec = 0
181 do while (reactants%get_key(spec_name))
182 ! Get properties included with this reactant in the reaction data
183 call assert(626170799, reactants%get_property_t(val=spec_props))
184 key_name = "qty"
185 if (spec_props%get_int(key_name, temp_int)) i_spec = i_spec+temp_int-1
186 call reactants%iter_next()
187 i_spec = i_spec + 1
188 end do
189
190 ! Allocate space in the condensed data arrays
191 allocate(this%condensed_data_int(num_int_prop_ + &
192 (i_spec + 2) * (i_spec + alkoxy_products%size() + &
193 nitrate_products%size())))
194 allocate(this%condensed_data_real(num_real_prop_ + &
195 alkoxy_products%size() + nitrate_products%size()))
196 this%condensed_data_int(:) = int(0, kind=i_kind)
197 this%condensed_data_real(:) = real(0.0, kind=dp)
198
199 ! Save space for the environment dependent parameters
200 this%num_env_params = num_env_param_
201
202 ! Save the size of the reactant and product arrays (for reactions where
203 ! these can vary)
204 num_react_ = i_spec
205 num_alkoxy_prod_ = alkoxy_products%size()
206 num_nitrate_prod_ = nitrate_products%size()
207
208 ! Set the #/cc -> ppm conversion prefactor
209 conv_ = const%avagadro / const%univ_gas_const * 10.0d0**(-12.0d0)
210
211 ! Get reaction parameters (it might be easiest to keep these at the
212 ! beginning of the condensed data array, so they can be accessed using
213 ! compliler flags)
214 key_name = "X"
215 if (.not. this%property_set%get_real(key_name, x_)) then
216 x_ = 1.0
217 end if
218 key_name = "time unit"
219 if (this%property_set%get_string(key_name, string_val)) then
220 if (trim(string_val).eq."MIN") then
221 x_ = x_ / 60.0
222 end if
223 endif
224 key_name = "Y"
225 if (.not. this%property_set%get_real(key_name, y_)) then
226 y_ = 0.0
227 end if
228 key_name = "a0"
229 if (.not. this%property_set%get_real(key_name, a0_)) then
230 a0_ = 1.0
231 end if
232 key_name = "n"
233 if (.not. this%property_set%get_real(key_name, n_)) then
234 n_ = 0.0
235 end if
236
237 ! Get the indices and chemical properties for the reactants
238 call reactants%iter_reset()
239 i_spec = 1
240 do while (reactants%get_key(spec_name))
241
242 ! Save the index of this species in the state variable array
243 react_(i_spec) = chem_spec_data%gas_state_id(spec_name)
244
245 ! Make sure the species exists
246 call assert_msg(716430972, react_(i_spec).gt.0, &
247 "Missing Wennberg NO + RO2 reactant: "//spec_name)
248
249 ! Get properties included with this reactant in the reaction data
250 call assert(493699816, reactants%get_property_t(val=spec_props))
251 key_name = "qty"
252 if (spec_props%get_int(key_name, temp_int)) then
253 do i_qty = 1, temp_int - 1
254 react_(i_spec + i_qty) = react_(i_spec)
255 end do
256 i_spec = i_spec + temp_int - 1
257 end if
258
259 call reactants%iter_next()
260 i_spec = i_spec + 1
261 end do
262
263 ! Get the indices and chemical properties for the products
264 call alkoxy_products%iter_reset()
265 i_spec = 1
266 do while (alkoxy_products%get_key(spec_name))
267
268 ! Save the index of this species in the state variable array
269 prod_(i_spec) = chem_spec_data%gas_state_id(spec_name)
270
271 ! Make sure the species exists
272 call assert_msg(825390544, prod_(i_spec).gt.0, &
273 "Missing Wennberg NO + RO2 alkoxy product: "//spec_name)
274
275 ! Get properties included with this product in the reaction data
276 call assert(879870330, alkoxy_products%get_property_t(val=spec_props))
277 key_name = "yield"
278 if (spec_props%get_real(key_name, temp_real)) then
279 yield_(i_spec) = temp_real
280 else
281 yield_(i_spec) = 1.0
282 end if
283
284 call alkoxy_products%iter_next()
285 i_spec = i_spec + 1
286 end do
287 call nitrate_products%iter_reset()
288 do while (nitrate_products%get_key(spec_name))
289
290 ! Save the index of this species in the state variable array
291 prod_(i_spec) = chem_spec_data%gas_state_id(spec_name)
292
293 ! Make sure the species exists
294 call assert_msg(590677535, prod_(i_spec).gt.0, &
295 "Missing Wennberg NO + RO2 nitrate product: "//spec_name)
296
297 ! Get properties included with this product in the reaction data
298 call assert(815314225, nitrate_products%get_property_t(val=spec_props))
299 key_name = "yield"
300 if (spec_props%get_real(key_name, temp_real)) then
301 yield_(i_spec) = temp_real
302 else
303 yield_(i_spec) = 1.0
304 end if
305
306 call nitrate_products%iter_next()
307 i_spec = i_spec + 1
308 end do
309 call assert(699637107, i_spec - 1 .eq. &
310 num_alkoxy_prod_ + num_nitrate_prod_ )
311
312 end subroutine initialize
313
314!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
315
316 !> Finalize the reaction
317 elemental subroutine finalize(this)
318
319 !> Reaction data
320 type(rxn_wennberg_no_ro2_t), intent(inout) :: this
321
322 if (associated(this%property_set)) &
323 deallocate(this%property_set)
324 if (allocated(this%condensed_data_real)) &
325 deallocate(this%condensed_data_real)
326 if (allocated(this%condensed_data_int)) &
327 deallocate(this%condensed_data_int)
328
329 end subroutine finalize
330
331!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
332
Initialize the aerosol representation data, validating component data and loading any required inform...
Get the non-unique name of a chemical species by its unique name.
Interface for to_string functions.
Definition util.F90:32
The abstract aero_rep_data_t structure and associated subroutines.
The camp_state_t structure and associated subroutines.
Definition camp_state.F90:9
elemental subroutine finalize(this)
Finalize the state.
The chem_spec_data_t structure and associated subroutines.
type(chem_spec_data_t) function, pointer constructor(init_size)
Constructor for chem_spec_data_t.
Physical constants.
Definition constants.F90:9
integer, parameter dp
Kind of a double precision real number.
Definition constants.F90:16
type(const_t), save const
Fixed variable for accessing the constant's values.
Definition constants.F90:77
integer, parameter i_kind
Kind of an integer.
Definition constants.F90:21
The property_t structure and associated subroutines.
Definition property.F90:9
The rxn_data_t structure and associated subroutines.
Definition rxn_data.F90:60
integer(kind=i_kind), parameter, public gas_rxn
Gas-phase reaction.
Definition rxn_data.F90:84
The rxn_wennberg_no_ro2_t type and associated functions.
Common utility subroutines.
Definition util.F90:9
subroutine assert(code, condition_ok)
Errors unless condition_ok is true.
Definition util.F90:165
subroutine die_msg(code, error_msg)
Error immediately.
Definition util.F90:196
subroutine assert_msg(code, condition_ok, error_msg)
Errors unless condition_ok is true.
Definition util.F90:130
#define a0_
#define n_
Pointer to aero_rep_data_t extending types.
Abstract reaction data type.
Definition rxn_data.F90:98