144 subroutine initialize(this, chem_spec_data, aero_rep, n_cells)
153 integer(kind=i_kind),
intent(in) :: n_cells
155 type(
property_t),
pointer :: products, spec_props
156 character(len=:),
allocatable :: key_name, reactant_name, product_name, &
157 phase_name, error_msg
158 integer :: i_spec, n_aero_jac_elem, n_aero_phase, i_phase, i_aero_rep, &
160 integer,
allocatable :: phase_ids(:)
161 real(kind=
dp) :: temp_real
163 if (.not.
associated(this%property_set))
call die_msg(244070915, &
164 "Missing property set needed to initialize surface reaction.")
166 key_name =
"gas-phase reactant"
168 this%property_set%get_string(key_name, reactant_name), &
169 "Missing gas-phase reactant name in surface reaction.")
171 key_name =
"gas-phase products"
173 this%property_set%get_property_t(key_name, products), &
174 "Missing gas-phase products for surface reaction.")
176 key_name =
"aerosol phase"
178 this%property_set%get_string(key_name, phase_name), &
179 "Missing aerosol phase in surface reaction.")
181 error_msg =
" for surface reaction of gas-phase species '"// &
182 reactant_name//
"' on aerosol phase '"//phase_name//
"'"
184 call assert(362731302,
associated(aero_rep))
185 call assert_msg(187310091,
size(aero_rep) .gt. 0, &
186 "Missing aerosol representation"//error_msg)
192 do i_aero_rep = 1,
size(aero_rep)
193 phase_ids = aero_rep(i_aero_rep)%val%phase_ids(phase_name, is_at_surface=.true.)
194 n_aero_phase = n_aero_phase +
size(phase_ids)
195 do i_phase = 1,
size(phase_ids)
196 n_aero_jac_elem = n_aero_jac_elem + &
197 aero_rep(i_aero_rep)%val%num_jac_elem(phase_ids(i_phase))
201 allocate(this%condensed_data_int(num_int_prop_ &
202 + 2 + 3 * products%size() &
205 + (1 + products%size()) * n_aero_jac_elem))
206 allocate(this%condensed_data_real(num_real_prop_ &
208 + 2 * n_aero_jac_elem))
209 this%condensed_data_int(:) = 0_i_kind
210 this%condensed_data_real(:) = 0.0_dp
213 this%num_env_params = num_env_param_
215 num_aero_phase_ = n_aero_phase
217 key_name =
"reaction probability"
219 this%property_set%get_real(key_name, gamma_), &
220 "Missing reaction probability for"//error_msg)
223 react_id_ = chem_spec_data%gas_state_id(reactant_name)
224 call assert_msg(908581300, react_id_ .gt. 0, &
225 "Missing gas-phase species"//error_msg)
227 chem_spec_data%get_property_set(reactant_name, spec_props), &
228 "Missing gas-phase species properties"//error_msg)
229 key_name =
"molecular weight [kg mol-1]"
230 call assert_msg(110823327, spec_props%get_real(key_name, mw_), &
231 "Missing molecular weight for gas-phase reactant"//error_msg)
232 key_name =
"diffusion coeff [m2 s-1]"
233 call assert_msg(860403969, spec_props%get_real(key_name, diff_coeff_), &
234 "Missing diffusion coefficient for gas-phase reactant"// &
238 num_prod_ = products%size()
239 call products%iter_reset()
241 do while (products%get_key(product_name))
242 prod_id_(i_spec) = chem_spec_data%gas_state_id(product_name)
243 call assert_msg(863839516, prod_id_(i_spec) .gt. 0, &
244 "Missing surface reaction product: "//product_name)
245 call assert(237691686, products%get_property_t(val=spec_props))
246 yield_(i_spec) = 1.0_dp
248 if (spec_props%get_real(key_name, temp_real)) yield_(i_spec) = temp_real
249 call products%iter_next()
255 phase_int_loc_(i_aero_id) = num_int_prop_ + 2 + 3 * num_prod_ + &
256 2 * num_aero_phase_ + 1
257 phase_real_loc_(i_aero_id) = num_real_prop_ + num_prod_ + 1
258 do i_aero_rep = 1,
size(aero_rep)
259 phase_ids = aero_rep(i_aero_rep)%val%phase_ids(phase_name, is_at_surface=.true.)
260 do i_phase = 1,
size(phase_ids)
261 num_aero_phase_jac_elem_(i_aero_id) = &
262 aero_rep(i_aero_rep)%val%num_jac_elem(phase_ids(i_phase))
263 aero_phase_id_(i_aero_id) = phase_ids(i_phase)
264 aero_rep_id_(i_aero_id) = i_aero_rep
265 i_aero_id = i_aero_id + 1
266 if (i_aero_id .le. num_aero_phase_)
then
267 phase_int_loc_(i_aero_id) = phase_int_loc_(i_aero_id - 1) + 3 + &
269 num_aero_phase_jac_elem_(i_aero_id - 1)
270 phase_real_loc_(i_aero_id) = phase_real_loc_(i_aero_id - 1) + &
271 2 * num_aero_phase_jac_elem_(i_aero_id - 1)