CAMP 1.0.0
Chemistry Across Multiple Phases
rxn_arrhenius.F90
Go to the documentation of this file.
1! Copyright (C) 2021 Barcelona Supercomputing Center and University of
2! Illinois at Urbana-Champaign
3! SPDX-License-Identifier: MIT
4
5!> \file
6!> The camp_rxn_arrhenius module.
7
8!> \page camp_rxn_arrhenius CAMP: Arrhenius Reaction
9!!
10!! Arrhenius-like reaction rate constant equations are calculated as follows:
11!!
12!! \f[
13!! Ae^{(\frac{-E_a}{k_bT})}(\frac{T}{D})^B(1.0+E*P)
14!! \f]
15!!
16!! where \f$A\f$ is the pre-exponential factor
17!! (# \f$(\mbox{cm}^{-3})^{-(n-1)}\mbox{s}^{-1}\f$),
18!! \f$n\f$ is the number of reactants, \f$E_a\f$ is the activation energy (J),
19!! \f$k_b\f$ is the Boltzmann constant (J/K), \f$D\f$ (K), \f$B\f$ (unitless)
20!! and \f$E\f$ (\f$Pa^{-1}\f$) are reaction parameters, \f$T\f$ is the
21!! temperature (K), and \f$P\f$ is the pressure (Pa). The first two terms are
22!! described in Finlayson-Pitts and Pitts (2000) \cite Finlayson-Pitts2000 .
23!! The final term is included to accomodate CMAQ EBI solver type 7 rate
24!! constants.
25!!
26!! Input data for Arrhenius equations has the following format:
27!! \code{.json}
28!! {
29!! "type" : "ARRHENIUS",
30!! "A" : 123.45,
31!! "Ea" : 123.45,
32!! "B" : 1.3,
33!! "D" : 300.0,
34!! "E" : 0.6E-5,
35!! "time unit" : "MIN",
36!! "reactants" : {
37!! "spec1" : {},
38!! "spec2" : { "qty" : 2 },
39!! ...
40!! },
41!! "products" : {
42!! "spec3" : {},
43!! "spec4" : { "yield" : 0.65 },
44!! ...
45!! }
46!! }
47!! \endcode
48!! The key-value pairs \b reactants, and \b products are required. Reactants
49!! without a \b qty value are assumed to appear once in the reaction equation.
50!! Products without a specified \b yield are assumed to have a \b yield of
51!! 1.0.
52!!
53!! Optionally, a parameter \b C may be included, and is taken to equal
54!! \f$\frac{-E_a}{k_b}\f$. Note that either \b Ea or \b C may be included, but
55!! not both. When neither \b Ea or \b C are included, they are assumed to be
56!! 0.0. When \b A is not included, it is assumed to be 1.0, when \b D is not
57!! included, it is assumed to be 300.0 K, when \b B is not included, it is
58!! assumed to be 0.0, and when \b E is not included, it is assumed to be 0.0.
59!! The unit for time is assumed to be s, but inclusion of the optional
60!! key-value pair \b time \b unit = \b MIN can be used to indicate a rate
61!! with min as the time unit.
62
63!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
64
65!> The rxn_arrhenius_t type and associated functions.
67
70 use camp_constants, only: const
74 use camp_util, only: i_kind, dp, to_string, &
76
77 implicit none
78 private
79
80#define NUM_REACT_ this%condensed_data_int(1)
81#define NUM_PROD_ this%condensed_data_int(2)
82#define A_ this%condensed_data_real(1)
83#define B_ this%condensed_data_real(2)
84#define C_ this%condensed_data_real(3)
85#define D_ this%condensed_data_real(4)
86#define E_ this%condensed_data_real(5)
87#define CONV_ this%condensed_data_real(6)
88#define NUM_INT_PROP_ 2
89#define NUM_REAL_PROP_ 6
90#define NUM_ENV_PARAM_ 1
91#define REACT_(x) this%condensed_data_int(NUM_INT_PROP_ + x)
92#define PROD_(x) this%condensed_data_int(NUM_INT_PROP_ + NUM_REACT_ + x)
93#define DERIV_ID_(x) this%condensed_data_int(NUM_INT_PROP_ + NUM_REACT_ + NUM_PROD_ + x)
94#define JAC_ID_(x) this%condensed_data_int(NUM_INT_PROP_ + 2*(NUM_REACT_+NUM_PROD_) + x)
95#define YIELD_(x) this%condensed_data_real(NUM_REAL_PROP_ + x)
96
97 public :: rxn_arrhenius_t
98
99 !> Generic test reaction data type
100 type, extends(rxn_data_t) :: rxn_arrhenius_t
101 contains
102 !> Reaction initialization
103 procedure :: initialize
104 !> Finalize the reaction
105 final :: finalize
106 end type rxn_arrhenius_t
107
108 !> Constructor for rxn_arrhenius_t
109 interface rxn_arrhenius_t
110 procedure :: constructor
111 end interface rxn_arrhenius_t
112
113contains
114
115!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
116
117 !> Constructor for Arrhenius reaction
118 function constructor() result(new_obj)
119
120 !> A new reaction instance
121 type(rxn_arrhenius_t), pointer :: new_obj
122
123 allocate(new_obj)
124 new_obj%rxn_phase = gas_rxn
125
126 end function constructor
127
128!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
129
130 !> Initialize the reaction data, validating component data and loading
131 !! any required information into the condensed data arrays for use during
132 !! solving
133 subroutine initialize(this, chem_spec_data, aero_rep, n_cells)
134
135 !> Reaction data
136 class(rxn_arrhenius_t), intent(inout) :: this
137 !> Chemical species data
138 type(chem_spec_data_t), intent(in) :: chem_spec_data
139 !> Aerosol representations
140 type(aero_rep_data_ptr), pointer, intent(in) :: aero_rep(:)
141 !> Number of grid cells being solved simultaneously
142 integer(kind=i_kind), intent(in) :: n_cells
143
144 type(property_t), pointer :: spec_props, reactants, products
145 character(len=:), allocatable :: key_name, spec_name, string_val
146 integer(kind=i_kind) :: i_spec, i_qty
147
148 integer(kind=i_kind) :: temp_int
149 real(kind=dp) :: temp_real
150
151 ! Get the species involved
152 if (.not. associated(this%property_set)) call die_msg(255324828, &
153 "Missing property set needed to initialize reaction")
154 key_name = "reactants"
155 call assert_msg(250060521, &
156 this%property_set%get_property_t(key_name, reactants), &
157 "Arrhenius reaction is missing reactants")
158 key_name = "products"
159 call assert_msg(304540307, &
160 this%property_set%get_property_t(key_name, products), &
161 "Arrhenius reaction is missing products")
162
163 ! Count the number of reactants (including those with a qty specified)
164 call reactants%iter_reset()
165 i_spec = 0
166 do while (reactants%get_key(spec_name))
167 ! Get properties included with this reactant in the reaction data
168 call assert(243342975, reactants%get_property_t(val=spec_props))
169 key_name = "qty"
170 if (spec_props%get_int(key_name, temp_int)) i_spec = i_spec+temp_int-1
171 call reactants%iter_next()
172 i_spec = i_spec + 1
173 end do
174
175 ! Allocate space in the condensed data arrays
176 allocate(this%condensed_data_int(num_int_prop_ + &
177 (i_spec + 2) * (i_spec + products%size())))
178 allocate(this%condensed_data_real(num_real_prop_ + products%size()))
179 this%condensed_data_int(:) = int(0, kind=i_kind)
180 this%condensed_data_real(:) = real(0.0, kind=dp)
181
182 ! Save space for the environment dependent parameters
183 this%num_env_params = num_env_param_
184
185 ! Save the size of the reactant and product arrays (for reactions where
186 ! these can vary)
187 num_react_ = i_spec
188 num_prod_ = products%size()
189
190 ! Set the #/cc -> ppm conversion prefactor
191 conv_ = const%avagadro / const%univ_gas_const * 10.0d0**(-12.0d0)
192
193 ! Get reaction parameters (it might be easiest to keep these at the
194 ! beginning of the condensed data array, so they can be accessed using
195 ! compliler flags)
196 key_name = "A"
197 if (.not. this%property_set%get_real(key_name, a_)) then
198 a_ = 1.0
199 end if
200 key_name = "time unit"
201 if (this%property_set%get_string(key_name, string_val)) then
202 if (trim(string_val).eq."MIN") then
203 a_ = a_ / 60.0
204 end if
205 endif
206 key_name = "Ea"
207 if (this%property_set%get_real(key_name, temp_real)) then
208 c_ = -temp_real/const%boltzmann
209 key_name = "C"
210 call assert_msg(297370315, &
211 .not.this%property_set%get_real(key_name, temp_real), &
212 "Received both Ea and C parameter for Arrhenius equation")
213 else
214 key_name = "C"
215 if (.not. this%property_set%get_real(key_name, c_)) then
216 c_ = 0.0
217 end if
218 end if
219 key_name = "D"
220 if (.not. this%property_set%get_real(key_name, d_)) then
221 d_ = 300.0
222 end if
223 key_name = "B"
224 if (.not. this%property_set%get_real(key_name, b_)) then
225 b_ = 0.0
226 end if
227 key_name = "E"
228 if (.not. this%property_set%get_real(key_name, e_)) then
229 e_ = 0.0
230 end if
231
232 call assert_msg(344705857, .not. ((b_.ne.real(0.0, kind=dp)) &
233 .and.(d_.eq.real(0.0, kind=dp))), &
234 "D cannot be zero if B is non-zero in Arrhenius reaction.")
235
236 ! Get the indices and chemical properties for the reactants
237 call reactants%iter_reset()
238 i_spec = 1
239 do while (reactants%get_key(spec_name))
240
241 ! Save the index of this species in the state variable array
242 react_(i_spec) = chem_spec_data%gas_state_id(spec_name)
243
244 ! Make sure the species exists
245 call assert_msg(751684145, react_(i_spec).gt.0, &
246 "Missing Arrhenius reactant: "//spec_name)
247
248 ! Get properties included with this reactant in the reaction data
249 call assert(796763915, reactants%get_property_t(val=spec_props))
250 key_name = "qty"
251 if (spec_props%get_int(key_name, temp_int)) then
252 do i_qty = 1, temp_int - 1
253 react_(i_spec + i_qty) = react_(i_spec)
254 end do
255 i_spec = i_spec + temp_int - 1
256 end if
257
258 call reactants%iter_next()
259 i_spec = i_spec + 1
260 end do
261
262 ! Get the indices and chemical properties for the products
263 call products%iter_reset()
264 i_spec = 1
265 do while (products%get_key(spec_name))
266
267 ! Save the index of this species in the state variable array
268 prod_(i_spec) = chem_spec_data%gas_state_id(spec_name)
269
270 ! Make sure the species exists
271 call assert_msg(234495887, prod_(i_spec).gt.0, &
272 "Missing Arrhenius product: "//spec_name)
273
274 ! Get properties included with this product in the reaction data
275 call assert(451185800, products%get_property_t(val=spec_props))
276 key_name = "yield"
277 if (spec_props%get_real(key_name, temp_real)) then
278 yield_(i_spec) = temp_real
279 else
280 yield_(i_spec) = 1.0
281 end if
282
283 call products%iter_next()
284 i_spec = i_spec + 1
285 end do
286
287 end subroutine initialize
288
289!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
290
291 !> Finalize the reaction
292 elemental subroutine finalize(this)
293
294 !> Reaction data
295 type(rxn_arrhenius_t), intent(inout) :: this
296
297 if (associated(this%property_set)) &
298 deallocate(this%property_set)
299 if (allocated(this%condensed_data_real)) &
300 deallocate(this%condensed_data_real)
301 if (allocated(this%condensed_data_int)) &
302 deallocate(this%condensed_data_int)
303
304 end subroutine finalize
305
306!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
307
308end module camp_rxn_arrhenius
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_arrhenius_t type and associated functions.
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
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
Pointer to aero_rep_data_t extending types.
Generic test reaction data type.
Abstract reaction data type.
Definition rxn_data.F90:98