CAMP 1.0.0
Chemistry Across Multiple Phases
rxn_troe.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_troe module.
7
8!> \page camp_rxn_troe CAMP: Troe Reaction
9!!
10!! Troe (fall-off) reaction rate constant equations take the form:
11!!
12!! \f[
13!! \frac{k_0[\mbox{M}]}{1+k_0[\mbox{M}]/k_{\inf}}F_C^{(1+1/N[log_{10}(k_0[\mbox{M}]/k_{\inf})]^2)^{-1}}
14!! \f]
15!!
16!! where \f$k_0\f$ is the low-pressure limiting rate constant, \f$k_{\inf}\f$
17!! is the high-pressure limiting rate constant, \f$[\mbox{M}]\f$ is the
18!! density of air, and \f$F_C\f$ and \f$N\f$ are parameters
19!! that determine the shape of the fall-off curve, and are typically 0.6 and
20!! 1.0, respectively \cite Finlayson-Pitts2000 \cite Gipson. \f$k_0\f$ and
21!! \f$k_{\inf}\f$ are calculated as \ref camp_rxn_arrhenius "Arrhenius" rate
22!! constants with \f$D=300\f$ and \f$E=0\f$.
23!!
24!! Input data for Troe reactions have the following format :
25!! \code{.json}
26!! {
27!! "type" : "TROE",
28!! "k0_A" : 5.6E-12,
29!! "k0_B" : -1.8,
30!! "k0_C" : 180.0,
31!! "kinf_A" : 3.4E-12,
32!! "kinf_B" : -1.6,
33!! "kinf_C" : 104.1,
34!! "Fc" : 0.7,
35!! "N" : 0.9,
36!! "time unit" : "MIN",
37!! "reactants" : {
38!! "spec1" : {},
39!! "spec2" : { "qty" : 2 },
40!! ...
41!! },
42!! "products" : {
43!! "spec3" : {},
44!! "spec4" : { "yield" : 0.65 },
45!! ...
46!! }
47!! }
48!! \endcode
49!! The key-value pairs \b reactants, and \b products are required. Reactants
50!! without a \b qty value are assumed to appear once in the reaction equation.
51!! Products without a specified \b yield are assumed to have a \b yield of
52!! 1.0.
53!!
54!! The two sets of parameters beginning with \b k0_ and \b kinf_ are the
55!! \ref camp_rxn_arrhenius "Arrhenius" parameters for the \f$k_0\f$ and
56!! \f$k_{\inf}\f$ rate constants, respectively. When not present, \b _A
57!! parameters are assumed to be 1.0, \b _B to be 0.0, \b _C to be 0.0, \b Fc
58!! to be 0.6 and \b N to be 1.0.
59!!
60!! The unit for time is assumed to be s, but inclusion of the optional
61!! key-value pair \b time \b unit = \b MIN can be used to indicate a rate
62!! with min as the time unit.
63
64!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
65
66!> The rxn_troe_t type and associated functions.
68
71 use camp_constants, only: const
75 use camp_util, only: i_kind, dp, to_string, &
77
78 implicit none
79 private
80
81#define NUM_REACT_ this%condensed_data_int(1)
82#define NUM_PROD_ this%condensed_data_int(2)
83#define K0_A_ this%condensed_data_real(1)
84#define K0_B_ this%condensed_data_real(2)
85#define K0_C_ this%condensed_data_real(3)
86#define KINF_A_ this%condensed_data_real(4)
87#define KINF_B_ this%condensed_data_real(5)
88#define KINF_C_ this%condensed_data_real(6)
89#define FC_ this%condensed_data_real(7)
90#define N_ this%condensed_data_real(8)
91#define SCALING_ this%condensed_data_real(9)
92#define CONV_ this%condensed_data_real(10)
93#define NUM_INT_PROP_ 2
94#define NUM_REAL_PROP_ 10
95#define NUM_ENV_PARAM_ 1
96#define REACT_(x) this%condensed_data_int(NUM_INT_PROP_ + x)
97#define PROD_(x) this%condensed_data_int(NUM_INT_PROP_ + NUM_REACT_ + x)
98#define DERIV_ID_(x) this%condensed_data_int(NUM_INT_PROP_ + NUM_REACT_ + NUM_PROD_ + x)
99#define JAC_ID_(x) this%condensed_data_int(NUM_INT_PROP_ + 2*(NUM_REACT_+NUM_PROD_) + x)
100#define YIELD_(x) this%condensed_data_real(NUM_REAL_PROP_ + x)
101
102public :: rxn_troe_t
103
104 !> Generic test reaction data type
105 type, extends(rxn_data_t) :: rxn_troe_t
106 contains
107 !> Reaction initialization
108 procedure :: initialize
109 !> Finalize the reaction
110 final :: finalize
111 end type rxn_troe_t
112
113 !> Constructor for rxn_troe_t
114 interface rxn_troe_t
115 procedure :: constructor
116 end interface rxn_troe_t
117
118contains
119
120!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
121
122 !> Constructor for Troe reaction
123 function constructor() result(new_obj)
124
125 !> A new reaction instance
126 type(rxn_troe_t), pointer :: new_obj
127
128 allocate(new_obj)
129 new_obj%rxn_phase = gas_rxn
130
131 end function constructor
132
133!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
134
135 !> Initialize the reaction data, validating component data and loading
136 !! any required information into the condensed data arrays for use during
137 !! solving
138 subroutine initialize(this, chem_spec_data, aero_rep, n_cells)
139
140 !> Reaction data
141 class(rxn_troe_t), intent(inout) :: this
142 !> Chemical species data
143 type(chem_spec_data_t), intent(in) :: chem_spec_data
144 !> Aerosol representations
145 type(aero_rep_data_ptr), pointer, intent(in) :: aero_rep(:)
146 !> Number of grid cells to solve simultaneously
147 integer(kind=i_kind), intent(in) :: n_cells
148
149 type(property_t), pointer :: spec_props, reactants, products
150 character(len=:), allocatable :: key_name, spec_name, string_val
151 integer(kind=i_kind) :: i_spec, i_qty
152
153 integer(kind=i_kind) :: temp_int
154 real(kind=dp) :: temp_real
155
156 ! Get the species involved
157 if (.not. associated(this%property_set)) call die_msg(510658779, &
158 "Missing property set needed to initialize reaction")
159 key_name = "reactants"
160 call assert_msg(852878121, &
161 this%property_set%get_property_t(key_name, reactants), &
162 "Troe reaction is missing reactants")
163 key_name = "products"
164 call assert_msg(965196466, &
165 this%property_set%get_property_t(key_name, products), &
166 "Troe reaction is missing products")
167
168 ! Count the number of reactants (including those with a qty specified)
169 call reactants%iter_reset()
170 i_spec = 0
171 do while (reactants%get_key(spec_name))
172 ! Get properties included with this reactant in the reaction data
173 call assert(844081716, reactants%get_property_t(val=spec_props))
174 key_name = "qty"
175 if (spec_props%get_int(key_name, temp_int)) i_spec = i_spec+temp_int-1
176 call reactants%iter_next()
177 i_spec = i_spec + 1
178 end do
179
180 ! Allocate space in the condensed data arrays
181 ! Space in this example is allocated for two sets of inidices for the
182 ! reactants and products, one molecular property for each reactant,
183 ! yields for the products and three reaction parameters.
184 allocate(this%condensed_data_int(num_int_prop_ + &
185 (i_spec + 2) * (i_spec + products%size())))
186 allocate(this%condensed_data_real(num_real_prop_ + products%size()))
187 this%condensed_data_int(:) = int(0, kind=i_kind)
188 this%condensed_data_real(:) = real(0.0, kind=dp)
189
190 ! Save space for the environment-dependent parameters
191 this%num_env_params = num_env_param_
192
193 ! Save the size of the reactant and product arrays (for reactions where
194 ! these can vary)
195 num_react_ = i_spec
196 num_prod_ = products%size()
197
198 ! Set the #/cc -> ppm conversion prefactor
199 conv_ = const%avagadro / const%univ_gas_const * 10.0d0**(-12.0d0)
200
201 ! Get reaction parameters (it might be easiest to keep these at the
202 ! beginning of the condensed data array, so they can be accessed using
203 ! compliler flags)
204 key_name = "k0_A"
205 if (.not. this%property_set%get_real(key_name, k0_a_)) then
206 k0_a_ = 1.0
207 end if
208 key_name = "k0_B"
209 if (.not. this%property_set%get_real(key_name, k0_b_)) then
210 k0_b_ = 0.0
211 end if
212 key_name = "k0_C"
213 if (.not. this%property_set%get_real(key_name, k0_c_)) then
214 k0_c_ = 0.0
215 end if
216 key_name = "kinf_A"
217 if (.not. this%property_set%get_real(key_name, kinf_a_)) then
218 kinf_a_ = 1.0
219 end if
220 key_name = "kinf_B"
221 if (.not. this%property_set%get_real(key_name, kinf_b_)) then
222 kinf_b_ = 0.0
223 end if
224 key_name = "kinf_C"
225 if (.not. this%property_set%get_real(key_name, kinf_c_)) then
226 kinf_c_ = 0.0
227 end if
228 key_name = "Fc"
229 if (.not. this%property_set%get_real(key_name, fc_)) then
230 fc_ = 0.6
231 end if
232 key_name = "N"
233 if (.not. this%property_set%get_real(key_name, n_)) then
234 n_ = 1.0
235 end if
236 key_name = "time unit"
237 scaling_ = real(1.0, kind=dp)
238 if (this%property_set%get_string(key_name, string_val)) then
239 if (trim(string_val).eq."MIN") then
240 scaling_ = real(1.0d0/60.0d0, kind=dp)
241 end if
242 endif
243
244 ! Include [M] in K0_A_
245 k0_a_ = k0_a_ * real(1.0d6, kind=dp)
246
247 ! Get the indices and chemical properties for the reactants
248 call reactants%iter_reset()
249 i_spec = 1
250 do while (reactants%get_key(spec_name))
251
252 ! Save the index of this species in the state variable array
253 react_(i_spec) = chem_spec_data%gas_state_id(spec_name)
254
255 ! Make sure the species exists
256 call assert_msg(595701751, react_(i_spec).gt.0, &
257 "Missing Troe reactant: "//spec_name)
258
259 ! Get properties included with this reactant in the reaction data
260 call assert(221292659, reactants%get_property_t(val=spec_props))
261 key_name = "qty"
262 if (spec_props%get_int(key_name, temp_int)) then
263 do i_qty = 1, temp_int - 1
264 react_(i_spec + i_qty) = react_(i_spec)
265 end do
266 i_spec = i_spec + temp_int - 1
267 end if
268
269 call reactants%iter_next()
270 i_spec = i_spec + 1
271 end do
272
273 ! Get the indices and chemical properties for the products
274 call products%iter_reset()
275 i_spec = 1
276 do while (products%get_key(spec_name))
277
278 ! Save the index of this species in the state variable array
279 prod_(i_spec) = chem_spec_data%gas_state_id(spec_name)
280
281 ! Make sure the species exists
282 call assert_msg(480024633, prod_(i_spec).gt.0, &
283 "Missing Troe product: "//spec_name)
284
285 ! Get properties included with this product in the reaction data
286 call assert(393355097, products%get_property_t(val=spec_props))
287 key_name = "yield"
288 if (spec_props%get_real(key_name, temp_real)) then
289 yield_(i_spec) = temp_real
290 else
291 yield_(i_spec) = 1.0
292 end if
293
294 call products%iter_next()
295 i_spec = i_spec + 1
296 end do
297
298 end subroutine initialize
299
300!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
301
302 !> Finalize the reaction
303 elemental subroutine finalize(this)
304
305 !> Reaction data
306 type(rxn_troe_t), intent(inout) :: this
307
308 if (associated(this%property_set)) &
309 deallocate(this%property_set)
310 if (allocated(this%condensed_data_real)) &
311 deallocate(this%condensed_data_real)
312 if (allocated(this%condensed_data_int)) &
313 deallocate(this%condensed_data_int)
314
315 end subroutine finalize
316
317!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
318
319end module camp_rxn_troe
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_troe_t type and associated functions.
Definition rxn_troe.F90:67
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 n_
Pointer to aero_rep_data_t extending types.
Abstract reaction data type.
Definition rxn_data.F90:98
Generic test reaction data type.
Definition rxn_troe.F90:105