181 subroutine initialize(this, chem_spec_data, aero_rep, n_cells)
190 integer(kind=i_kind),
intent(in) :: n_cells
192 type(
property_t),
pointer :: spec_props, b_params
193 character(len=:),
allocatable :: key_name, gas_spec_name, aero_spec_name
194 character(len=:),
allocatable :: phase_name, act_name, error_msg
195 integer(kind=i_kind) :: i_spec, i_aero_rep, n_aero_ids, i_aero_id
196 integer(kind=i_kind) :: i_phase, n_aero_jac_elem, tmp_size
197 type(
string_t),
allocatable :: unique_spec_names(:), unique_act_names(:)
198 integer(kind=i_kind),
allocatable :: phase_ids(:)
199 real(kind=
dp) :: temp_real, n_star
200 logical :: has_act_coeff
203 if (.not.
associated(this%property_set))
call die_msg(382913491, &
204 "Missing property set needed to initialize reaction")
207 key_name =
"gas-phase species"
209 this%property_set%get_string(key_name, gas_spec_name), &
210 "Missing gas-phase species in SIMPOL.1 phase transfer reaction")
213 key_name =
"aerosol phase"
215 this%property_set%get_string(key_name, phase_name), &
216 "Missing aerosol phase in SIMPOL.1 phase-transfer reaction")
219 key_name =
"aerosol-phase species"
221 this%property_set%get_string(key_name, aero_spec_name), &
222 "Missing aerosol-phase species in SIMPOL.1 phase-transfer "// &
226 error_msg =
" for SIMPOL.1 phase transfer of gas species '"// &
227 gas_spec_name//
"' to aerosol-phase species '"// &
228 aero_spec_name//
"' in phase '"//phase_name//
"'"
231 key_name =
"aerosol-phase activity coefficient"
232 has_act_coeff = this%property_set%get_string(key_name, act_name)
235 call assert_msg(260518827,
associated(aero_rep), &
236 "Missing aerosol representation"//error_msg)
237 call assert_msg(590304021,
size(aero_rep).gt.0, &
238 "Missing aerosol representation"//error_msg)
243 do i_aero_rep = 1,
size(aero_rep)
247 unique_spec_names = aero_rep(i_aero_rep)%val%unique_names( &
248 phase_name = phase_name,
spec_name = aero_spec_name, &
249 phase_is_at_surface = .true.)
252 if (.not.
allocated(unique_spec_names)) cycle
255 n_aero_ids = n_aero_ids +
size(unique_spec_names)
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 n_aero_jac_elem = n_aero_jac_elem + &
262 aero_rep(i_aero_rep)%val%num_jac_elem(phase_ids(i_phase))
265 deallocate(unique_spec_names)
270 "Aerosol species not found"//error_msg)
273 allocate(this%condensed_data_int(num_int_prop_ + 2 + n_aero_ids * 13 + &
274 n_aero_jac_elem * 2))
275 allocate(this%condensed_data_real(num_real_prop_ + n_aero_jac_elem * 4))
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 properties"//error_msg)
291 key_name =
"molecular weight [kg mol-1]"
292 call assert_msg(839930958, spec_props%get_real(key_name, mw_), &
293 "Missing property 'MW'"//error_msg)
299 conv_ =
const%univ_gas_const / mw_ * 1.0e6
303 phase_int_loc_(i_aero_id) = num_int_prop_+12*num_aero_phase_+3
304 phase_real_loc_(i_aero_id) = num_real_prop_+1
305 do i_aero_rep = 1,
size(aero_rep)
309 unique_spec_names = aero_rep(i_aero_rep)%val%unique_names( &
310 phase_name = phase_name,
spec_name = aero_spec_name, &
311 phase_is_at_surface = .true.)
314 if (has_act_coeff)
then
315 unique_act_names = aero_rep(i_aero_rep)%val%unique_names( &
316 phase_name = phase_name,
spec_name = act_name, &
317 phase_is_at_surface = .true.)
318 call assert_msg(236251734,
size(unique_act_names).eq. &
319 size(unique_spec_names), &
320 "Mismatch of SIMPOL species and activity coeffs"// &
325 phase_ids = aero_rep(i_aero_rep)%val%phase_ids(phase_name, is_at_surface=.true.)
329 do i_spec = 1,
size(unique_spec_names)
330 num_aero_phase_jac_elem_(i_aero_id) = &
331 aero_rep(i_aero_rep)%val%num_jac_elem(phase_ids(i_spec))
332 aero_spec_(i_aero_id) = &
333 aero_rep(i_aero_rep)%val%spec_state_id( &
334 unique_spec_names(i_spec)%string)
335 if (has_act_coeff)
then
336 aero_act_id_(i_aero_id) = &
337 aero_rep(i_aero_rep)%val%spec_state_id( &
338 unique_act_names(i_spec)%string)
340 aero_act_id_(i_aero_id) = -1
342 aero_phase_id_(i_aero_id) = phase_ids(i_spec)
343 aero_rep_id_(i_aero_id) = i_aero_rep
344 i_aero_id = i_aero_id + 1
345 if (i_aero_id .le. num_aero_phase_)
then
346 phase_int_loc_(i_aero_id) = phase_int_loc_(i_aero_id - 1) + 1 + &
347 2*num_aero_phase_jac_elem_(i_aero_id - 1)
348 phase_real_loc_(i_aero_id) = phase_real_loc_(i_aero_id - 1) + &
349 4*num_aero_phase_jac_elem_(i_aero_id - 1)
353 deallocate(unique_spec_names)
360 this%property_set%get_property_t(key_name, b_params), &
361 "Missing 'B' parameters"//error_msg)
362 call assert_msg(654885723, b_params%size().eq.4, &
363 "Incorrect number of 'B' parameters"//error_msg)
364 call b_params%iter_reset()
365 call assert_msg(694024883, b_params%get_real(val = b1_), &
366 "Got non-real 'B1' parameter"//error_msg)
367 call b_params%iter_next()
368 call assert_msg(231316411, b_params%get_real(val = b2_), &
369 "Got non-real 'B2' parameter"//error_msg)
370 call b_params%iter_next()
371 call assert_msg(126167907, b_params%get_real(val = b3_), &
372 "Got non-real 'B3' parameter"//error_msg)
373 call b_params%iter_next()
374 call assert_msg(573535753, b_params%get_real(val = b4_), &
375 "Got non-real 'B4' parameter"//error_msg)
378 gas_spec_ = chem_spec_data%gas_state_id(gas_spec_name)
382 "Missing gas-phase species"//error_msg)
386 chem_spec_data%get_property_set(gas_spec_name, spec_props), &
387 "Missing properties for gas-phase species"//error_msg)
397 if (spec_props%get_real(key_name, n_star))
then
399 delta_h_ = real(- 10.0d0*(n_star-1.0d0) + &
400 7.53d0*(n_star**(2.0d0/3.0d0)-1.0d0) - 1.0d0, kind=
dp)
402 delta_s_ = real(- 32.0d0*(n_star-1.0d0) + &
403 9.21d0*(n_star**(2.0d0/3.0d0)-1.0d0) - 1.3d0, kind=
dp)
405 delta_h_ = real(delta_h_ * 4184.0d0, kind=
dp)
406 delta_s_ = real(delta_s_ * 4.184d0, kind=
dp)
408 delta_h_ = real(0.0, kind=
dp)
409 delta_s_ = real(0.0, kind=
dp)
413 key_name =
"diffusion coeff [m2 s-1]"
414 call assert_msg(948176709, spec_props%get_real(key_name, diff_coeff_), &
415 "Missing diffusion coefficient"//error_msg)
418 key_name =
"molecular weight [kg mol-1]"
419 call assert_msg(272813400, spec_props%get_real(key_name, temp_real), &
420 "Missing molecular weight"//error_msg)
421 pre_c_avg_ = sqrt(8.0*
const%univ_gas_const/(
const%pi*temp_real))
424 tmp_size = phase_int_loc_(i_aero_id - 1) + 1 + &
425 2*num_aero_phase_jac_elem_(i_aero_id - 1) - 1
426 call assert_msg(625802519,
size(this%condensed_data_int) .eq. tmp_size, &
427 "int array size mismatch"//error_msg)
428 tmp_size = phase_real_loc_(i_aero_id - 1) + &
429 4*num_aero_phase_jac_elem_(i_aero_id - 1) - 1
430 call assert_msg(391089510,
size(this%condensed_data_real) .eq. tmp_size, &
431 "real array size mismatch"//error_msg)