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