172 subroutine initialize(this, chem_spec_data, aero_rep, n_cells)
181 integer(kind=i_kind),
intent(in) :: n_cells
184 character(len=:),
allocatable :: key_name, gas_spec_name, &
185 water_name, aero_spec_name, phase_name, error_msg
186 integer(kind=i_kind) :: i_spec, i_aero_rep, n_aero_ids, i_aero_id, &
187 n_aero_jac_elem, i_phase, tmp_size
188 type(
string_t),
allocatable :: unique_spec_names(:), &
189 unique_water_names(:)
190 integer(kind=i_kind),
allocatable :: phase_ids(:)
191 real(kind=
dp) :: temp_real, n_star
194 if (.not.
associated(this%property_set))
call die_msg(318525776, &
195 "Missing property set needed to initialize reaction")
198 key_name =
"gas-phase species"
200 this%property_set%get_string(key_name, gas_spec_name), &
201 "Missing gas-phase species in phase-transfer reaction")
204 key_name =
"aerosol phase"
206 this%property_set%get_string(key_name, phase_name), &
207 "Missing aerosol phase in phase-transfer reaction")
210 key_name =
"aerosol-phase species"
212 this%property_set%get_string(key_name, aero_spec_name), &
213 "Missing aerosol-phase species in phase-transfer reaction")
216 error_msg =
" for HL partitioning reaction of gas-phase species '"// &
217 gas_spec_name//
"' to aerosol-phase species '"// &
218 aero_spec_name//
"' in phase '"//phase_name
221 key_name =
"aerosol-phase water"
223 this%property_set%get_string(key_name, water_name), &
224 "Missing aerosol-phase water"//error_msg)
227 call assert_msg(234155350,
associated(aero_rep), &
228 "Missing aerosol representation"//error_msg)
229 call assert_msg(207961800,
size(aero_rep).gt.0, &
230 "Missing aerosol representation"//error_msg)
236 do i_aero_rep = 1,
size(aero_rep)
240 unique_spec_names = aero_rep(i_aero_rep)%val%unique_names( &
241 phase_name = phase_name,
spec_name = aero_spec_name)
242 unique_water_names = aero_rep(i_aero_rep)%val%unique_names( &
243 phase_name = phase_name,
spec_name = water_name)
246 if (.not.
allocated(unique_spec_names)) cycle
249 call assert_msg(598091463,
size(unique_spec_names).eq. &
250 size(unique_water_names),
"Missing species "// &
251 aero_spec_name//
" or "//water_name//
" in phase "//phase_name// &
252 " or improper implementation of aerosol phase in aerosol "// &
253 "representation"//error_msg)
256 n_aero_ids = n_aero_ids +
size(unique_spec_names)
260 phase_ids = aero_rep(i_aero_rep)%val%phase_ids(phase_name, is_at_surface=.true.)
261 do i_phase = 1,
size(phase_ids)
262 n_aero_jac_elem = n_aero_jac_elem + &
263 aero_rep(i_aero_rep)%val%num_jac_elem(phase_ids(i_phase))
266 deallocate(unique_spec_names)
267 deallocate(unique_water_names)
272 allocate(this%condensed_data_int(num_int_prop_ + 2 + n_aero_ids * 13 + &
273 n_aero_jac_elem * 2))
274 allocate(this%condensed_data_real(num_real_prop_ + n_aero_ids + &
275 n_aero_jac_elem * 2))
276 this%condensed_data_int(:) = int(0, kind=
i_kind)
277 this%condensed_data_real(:) = real(0.0, kind=
dp)
280 this%num_env_params = num_env_param_
283 num_aero_phase_ = n_aero_ids
287 chem_spec_data%get_property_set(aero_spec_name, spec_props), &
288 "Missing aerosol species properties"//error_msg)
291 key_name =
"molecular weight [kg mol-1]"
292 call assert_msg(209812557, spec_props%get_real(key_name, mw_), &
293 "Missing property 'MW' for aerosol species"//error_msg)
297 conv_ =
const%univ_gas_const / mw_ * 1.0e6
300 key_name =
"aerosol-phase water"
302 this%property_set%get_string(key_name, water_name), &
303 "Missing aerosol-phase water"//error_msg)
307 phase_int_loc_(i_aero_id) = num_int_prop_+8*num_aero_phase_+3
308 phase_real_loc_(i_aero_id) = num_real_prop_+1
309 do i_aero_rep = 1,
size(aero_rep)
313 unique_spec_names = aero_rep(i_aero_rep)%val%unique_names( &
314 phase_name = phase_name,
spec_name = aero_spec_name)
315 unique_water_names = aero_rep(i_aero_rep)%val%unique_names( &
316 phase_name = phase_name,
spec_name = water_name)
319 phase_ids = aero_rep(i_aero_rep)%val%phase_ids(phase_name, is_at_surface=.true.)
324 do i_spec = 1,
size(unique_spec_names)
325 num_aero_phase_jac_elem_(i_aero_id) = &
326 aero_rep(i_aero_rep)%val%num_jac_elem(phase_ids(i_spec))
327 aero_spec_(i_aero_id) = &
328 aero_rep(i_aero_rep)%val%spec_state_id( &
329 unique_spec_names(i_spec)%string)
330 aero_water_(i_aero_id) = &
331 aero_rep(i_aero_rep)%val%spec_state_id( &
332 unique_water_names(i_spec)%string)
333 aero_phase_id_(i_aero_id) = phase_ids(i_spec)
334 aero_rep_id_(i_aero_id) = i_aero_rep
335 i_aero_id = i_aero_id + 1
336 if (i_aero_id .le. num_aero_phase_)
then
337 phase_int_loc_(i_aero_id) = phase_int_loc_(i_aero_id - 1) + 5 + &
338 2*num_aero_phase_jac_elem_(i_aero_id - 1)
339 phase_real_loc_(i_aero_id) = phase_real_loc_(i_aero_id - 1) + 1 + &
340 2*num_aero_phase_jac_elem_(i_aero_id - 1)
344 deallocate(unique_spec_names)
345 deallocate(unique_water_names)
350 gas_spec_ = chem_spec_data%gas_state_id(gas_spec_name)
354 "Missing gas-phase species"//error_msg)
358 chem_spec_data%get_property_set(gas_spec_name, spec_props), &
359 "Missing gas-phase species properties"//error_msg)
362 key_name =
"HLC(298K) [M Pa-1]"
363 call assert_msg(637925661, spec_props%get_real(key_name, a_), &
364 "Missing Henry's Law constant at 298 K"//error_msg)
366 key_name =
"HLC exp factor [K]"
367 call assert_msg(801365019, spec_props%get_real(key_name, c_), &
368 "Missing Henry's Law constant exponential factor"// &
379 if (spec_props%get_real(key_name, n_star))
then
381 delta_h_ = real(- 10.0d0*(n_star-1.0d0) + &
382 7.53d0*(n_star**(2.0d0/3.0d0)-1.0d0) - 1.0d0, kind=
dp)
384 delta_s_ = real(- 32.0d0*(n_star-1.0d0) + &
385 9.21d0*(n_star**(2.0d0/3.0d0)-1.0d0) - 1.3d0, kind=
dp)
387 delta_h_ = real(delta_h_ * 4184.0d0, kind=
dp)
388 delta_s_ = real(delta_s_ * 4.184d0, kind=
dp)
390 delta_h_ = real(0.0, kind=
dp)
391 delta_s_ = real(0.0, kind=
dp)
395 key_name =
"diffusion coeff [m2 s-1]"
396 call assert_msg(100205531, spec_props%get_real(key_name, diff_coeff_), &
397 "Missing diffusion coefficient for gas-phase species"//error_msg)
400 key_name =
"molecular weight [kg mol-1]"
401 call assert_msg(469582180, spec_props%get_real(key_name, temp_real), &
402 "Missing molecular weight for gas-phase species"//error_msg)
403 pre_c_avg_ = sqrt(8.0*
const%univ_gas_const/(
const%pi*temp_real))
406 tmp_size = phase_int_loc_(i_aero_id - 1) + 5 + &
407 2*num_aero_phase_jac_elem_(i_aero_id - 1) - 1
408 call assert_msg(881234422,
size(this%condensed_data_int) .eq. tmp_size, &
409 "int array size mismatch"//error_msg)
410 tmp_size = phase_real_loc_(i_aero_id - 1) + 1 + &
411 2*num_aero_phase_jac_elem_(i_aero_id - 1) - 1
412 call assert_msg(520767976,
size(this%condensed_data_real) .eq. tmp_size,&
413 "real array size mismatch"//error_msg)