143 subroutine initialize(this, chem_spec_data, aero_phase, aero_rep, n_cells)
154 integer(kind=i_kind),
intent(in) :: n_cells
156 type(
property_t),
pointer :: spec_props, reactants, products
157 character(len=:),
allocatable :: key_name, spec_name, water_name, &
158 phase_name, string_val, ion_pair_name
159 integer(kind=i_kind) :: i_phase_inst, j_spec, i_qty, i_aero_rep, &
160 i_aero_phase, num_spec_per_phase, num_phase, num_react, &
161 num_prod, temp_int, tracer_type
162 real(kind=
dp) :: temp_real
167 if (.not.
associated(this%property_set))
call die_msg(206493887, &
168 "Missing property set needed to initialize reaction")
171 key_name =
"aerosol phase"
173 this%property_set%get_string(key_name, phase_name), &
174 "Missing aerosol phase in aqueous-equilibrium reaction")
177 key_name =
"aerosol-phase water"
179 this%property_set%get_string(key_name, water_name), &
180 "Missing aerosol-phase water in aqueous-equilibrium reaction")
183 key_name =
"reactants"
185 this%property_set%get_property_t(key_name, reactants), &
186 "Missing reactant species in aqueous-equilibrium reaction")
189 key_name =
"products"
191 this%property_set%get_property_t(key_name, products), &
192 "Missing product species in aqueous-equilibrium reaction")
196 call reactants%iter_reset()
200 call assert(422080799, reactants%get_property_t(val=spec_props))
202 if (spec_props%get_int(key_name, temp_int)) &
203 num_react = num_react + temp_int - 1
204 call reactants%iter_next()
205 num_react = num_react + 1
207 call products%iter_reset()
211 call assert(971363961, products%get_property_t(val=spec_props))
213 if (spec_props%get_int(key_name, temp_int)) &
214 num_prod = num_prod + temp_int - 1
215 call products%iter_next()
216 num_prod = num_prod + 1
218 num_spec_per_phase = num_prod + num_react
221 call assert_msg(191050890,
associated(aero_rep), &
222 "Missing aerosol representation for aqueous equilibrium reaction")
223 call assert_msg(868319733,
size(aero_rep).gt.0, &
224 "Missing aerosol representation for aqueous equilibrium reaction")
228 do i_aero_rep = 1,
size(aero_rep)
231 if (aero_rep(i_aero_rep)%val%num_phase_instances(phase_name).eq.0) cycle
235 phase_name = phase_name,
spec_name = water_name)
237 "Missing aerosol-phase water species '"//water_name// &
238 "' in phase '"//phase_name//
"'")
240 "Missing aerosol-phase water species '"//water_name// &
241 "' in phase '"//phase_name//
"'")
253 "No aerosol phase '"//phase_name//
"' present.")
256 allocate(this%condensed_data_int(num_int_prop_ + &
257 num_phase * (num_spec_per_phase * (num_spec_per_phase + 4) + 2)))
258 allocate(this%condensed_data_real(num_real_prop_ + &
259 2 * num_spec_per_phase + 2 * num_phase))
260 this%condensed_data_int(:) = int(0, kind=
i_kind)
261 this%condensed_data_real(:) = real(0.0, kind=
dp)
264 this%num_env_params = num_env_param_
267 num_react_ = num_react
269 num_aero_phase_ = num_phase
273 if (.not. this%property_set%get_real(key_name, a_))
then
277 if (.not. this%property_set%get_real(key_name, c_))
then
280 key_name =
"k_reverse"
282 this%property_set%get_real(key_name, rate_const_reverse_), &
283 "Missing 'k_reverse' for aqueous equilibrium reaction")
284 key_name =
"time_unit"
285 if (this%property_set%get_string(key_name, string_val))
then
286 if (trim(string_val).eq.
"MIN")
then
287 rate_const_reverse_ = rate_const_reverse_ / 60.0
292 allocate(react_names(num_react_))
293 allocate(prod_names(num_prod_))
296 call reactants%iter_reset()
302 chem_spec_data%get_property_set(
spec_name, spec_props), &
303 "Missing properties required for aqueous equilibrium "// &
304 "reaction involving species '"//trim(
spec_name)//
"'")
307 key_name =
"molecular weight [kg mol-1]"
308 call assert_msg(332898361, spec_props%get_real(key_name, temp_real), &
309 "Missing 'molecular weight' for species '"//trim(
spec_name)// &
310 "' in aqueous equilibrium reaction.")
313 call assert(971363961, reactants%get_property_t(val=spec_props))
315 if (.not.spec_props%get_int(key_name, temp_int)) temp_int = 1
316 do i_qty = 1, temp_int
317 i_phase_inst = i_phase_inst + 1
320 react_names(i_phase_inst)%string =
spec_name
323 mass_frac_to_m_(i_phase_inst) = 1.0d3/temp_real
328 call reactants%iter_next()
333 call products%iter_reset()
339 chem_spec_data%get_property_set(
spec_name, spec_props), &
340 "Missing properties required for aqueous equilibrium "// &
341 "reaction involving species '"//trim(
spec_name)//
"'")
344 key_name =
"molecular weight [kg mol-1]"
345 call assert_msg(332898361, spec_props%get_real(key_name, temp_real), &
346 "Missing 'molecular weight' for species '"//trim(
spec_name)// &
347 "' in aqueous equilibrium reaction.")
350 call assert(294785742, products%get_property_t(val=spec_props))
352 if (.not.spec_props%get_int(key_name, temp_int)) temp_int = 1
353 do i_qty = 1, temp_int
354 i_phase_inst = i_phase_inst + 1
357 prod_names(i_phase_inst)%string =
spec_name
360 mass_frac_to_m_(num_react_ + i_phase_inst) = 1.0d3/temp_real
365 call products%iter_next()
371 key_name =
"ion pair"
372 if (.not. this%property_set%get_string(key_name, ion_pair_name))
then
378 do i_aero_rep = 1,
size(aero_rep)
381 if (aero_rep(i_aero_rep)%val%num_phase_instances(phase_name).eq.0) cycle
385 phase_name = phase_name,
spec_name = water_name)
392 do i_phase_inst = 1, num_phase
393 water_(i_aero_phase + i_phase_inst) = &
394 aero_rep(i_aero_rep)%val%spec_state_id( &
401 if (ion_pair_name.ne.
"")
then
405 phase_name = phase_name,
spec_name = ion_pair_name)
409 "Incorrect instances of ion pair '"//ion_pair_name// &
410 "' in phase '"//phase_name// &
411 "' in an aqueous equilibrium reaction")
415 chem_spec_data%get_type(ion_pair_name, tracer_type))
417 "Ion pair '"//ion_pair_name//
"' must have type "// &
418 "'ION_PAIR' to be used as an ion pair in an aqueous "// &
419 "equilibrium reaction.")
422 do i_phase_inst = 1, num_phase
423 activity_coeff_(i_aero_phase + i_phase_inst) = &
424 aero_rep(i_aero_rep)%val%spec_state_id( &
431 do i_phase_inst = 1, num_phase
432 activity_coeff_(i_aero_phase + i_phase_inst) = 0
437 do i_phase_inst = 1, num_react_
441 phase_name = phase_name, &
442 spec_name = react_names(i_phase_inst)%string)
446 "Incorrect instances of reactant '"// &
447 react_names(i_phase_inst)%string// &
448 "' in phase '"//phase_name// &
449 "' in an aqueous equilibrium reaction")
454 do j_spec = 1, num_phase
455 react_((i_aero_phase+j_spec-1)*num_react_ + i_phase_inst) = &
456 aero_rep(i_aero_rep)%val%spec_state_id( &
465 do i_phase_inst = 1, num_prod_
469 phase_name = phase_name, &
470 spec_name = prod_names(i_phase_inst)%string)
474 "Incorrect instances of product '"// &
475 prod_names(i_phase_inst)%string// &
476 "' in phase '"//phase_name// &
477 "' in an aqueous equilibrium reaction")
482 do j_spec = 1, num_phase
483 prod_((i_aero_phase+j_spec-1)*num_prod_ + i_phase_inst) = &
484 aero_rep(i_aero_rep)%val%spec_state_id( &
493 i_aero_phase = i_aero_phase + num_phase