188 subroutine initialize(this, chem_spec_data, aero_phase, aero_rep, n_cells)
199 integer(kind=i_kind),
intent(in) :: n_cells
201 type(
property_t),
pointer :: spec_props, reactants, products
202 character(len=:),
allocatable :: key_name, spec_name, water_name, &
203 phase_name, temp_string
204 integer(kind=i_kind) :: i_spec, i_phase_inst, i_qty, i_aero_rep, &
205 i_aero_phase, num_spec_per_phase, num_phase, num_react, num_prod
206 type(
string_t),
allocatable :: unique_names(:)
207 type(
string_t),
allocatable :: react_names(:), prod_names(:)
209 integer(kind=i_kind) :: temp_int
210 real(kind=
dp) :: temp_real
211 logical :: is_aqueous
216 call assert_msg(852163263,
associated(this%property_set), &
217 "Missing property set needed to initialize reaction")
220 key_name =
"aerosol phase"
222 this%property_set%get_string(key_name, phase_name), &
223 "Missing aerosol phase in condensed-phase Photolysis reaction")
226 key_name =
"reactants"
228 this%property_set%get_property_t(key_name, reactants), &
229 "Missing reactant species in condensed-phase Photolysis reaction")
232 key_name =
"products"
234 this%property_set%get_property_t(key_name, products), &
235 "Missing product species in condensed-phase Photolysis reaction")
239 call reactants%iter_reset()
243 call assert(428593951, reactants%get_property_t(val=spec_props))
245 if (spec_props%get_int(key_name, temp_int)) &
246 num_react = num_react + temp_int - 1
247 call reactants%iter_next()
248 num_react = num_react + 1
252 call assert_msg(890212987, num_react .eq. 1, &
253 "Too many species in condensed-phase Photolysis reaction. Only one reactant is expected.")
255 num_prod = products%size()
256 num_spec_per_phase = num_prod + num_react
259 call assert_msg(370755392,
associated(aero_rep), &
260 "Missing aerosol representation for condensed-phase "// &
261 "Photolysis reaction")
262 call assert_msg(483073737,
size(aero_rep).gt.0, &
263 "Missing aerosol representation for condensed-phase "// &
264 "Photolysis reaction")
268 do i_aero_rep = 1,
size(aero_rep)
269 num_phase = num_phase + &
270 aero_rep(i_aero_rep)%val%num_phase_instances(phase_name)
274 allocate(this%condensed_data_int(num_int_prop_ + &
275 num_phase * (num_spec_per_phase * (num_react + 3) + 1)))
276 allocate(this%condensed_data_real(num_real_prop_ + &
277 num_spec_per_phase + num_prod))
278 this%condensed_data_int(:) = int(0, kind=
i_kind)
279 this%condensed_data_real(:) = real(0.0, kind=
dp)
282 this%num_env_params = num_env_param_
285 num_react_ = num_react
287 num_aero_phase_ = num_phase
292 key_name =
"scaling factor"
293 if (.not. this%property_set%get_real(key_name, scaling_))
then
294 scaling_ = real(1.0, kind=
dp)
298 allocate(react_names(num_react_))
299 allocate(prod_names(num_prod_))
302 call reactants%iter_reset()
308 chem_spec_data%get_property_set(
spec_name, spec_props), &
309 "Missing properties required for condensed-phase Photolysis "// &
310 "reaction involving species '"//trim(
spec_name)//
"'")
313 key_name =
"molecular weight [kg mol-1]"
314 call assert_msg(409180731, spec_props%get_real(key_name, temp_real), &
315 "Missing 'molecular weight' for species '"//trim(
spec_name)// &
316 "' in condensed-phase Photolysis reaction.")
319 call assert(186449575, reactants%get_property_t(val=spec_props))
321 if (.not.spec_props%get_int(key_name, temp_int)) temp_int = 1
322 do i_qty = 1, temp_int
329 kgm3_to_molm3_(i_spec) = 1.0/temp_real
334 call reactants%iter_next()
339 call products%iter_reset()
345 chem_spec_data%get_property_set(
spec_name, spec_props), &
346 "Missing properties required for condensed-phase Photolysis "// &
347 "reaction involving species '"//trim(
spec_name)//
"'")
353 key_name =
"molecular weight [kg mol-1]"
354 call assert_msg(504705211, spec_props%get_real(key_name, temp_real), &
355 "Missing 'molecular weight' for species '"//trim(
spec_name)// &
356 "' in condensed phase Photolysis reaction.")
359 kgm3_to_molm3_(num_react_+i_spec) = 1.0/temp_real
362 call assert(846924553, products%get_property_t(val=spec_props))
364 if (spec_props%get_real(key_name, temp_real))
then
365 yield_(i_spec) = temp_real
367 yield_(i_spec) = 1.0d0
374 call products%iter_next()
382 this%property_set%get_string(key_name, temp_string), &
383 "Missing units for condensed-phase Photolysis reaction.")
384 if (trim(temp_string).eq.
"mol m-3")
then
386 key_name =
"aerosol-phase water"
388 .not.this%property_set%get_string(key_name, temp_string), &
389 "Aerosol-phase water specified for non-aqueous condensed-"// &
390 "phase Photolysis reaction. Change units to 'M' or remove "// &
391 "aerosol-phase water")
392 else if (trim(temp_string).eq.
"M")
then
394 key_name =
"aerosol-phase water"
396 this%property_set%get_string(key_name, water_name), &
397 "Missing aerosol-phase water for aqeuous condensed-phase "// &
398 "Photolysis reaction.")
400 call die_msg(161772048,
"Received invalid units for condensed-"// &
401 "phase Photolysis reaction: '"//temp_string//
"'. Valid "// &
402 "units are 'mol m-3' or 'M'.")
407 do i_aero_rep = 1,
size(aero_rep)
410 num_phase = aero_rep(i_aero_rep)%val%num_phase_instances(phase_name)
411 if (num_phase.eq.0) cycle
419 phase_name = phase_name,
spec_name = water_name)
423 "Missing aerosol-phase water species '"//water_name// &
424 "' in phase '"//phase_name//
"' in aqueous condensed-"// &
425 "phase Photolysis reacion.")
428 do i_phase_inst = 1, num_phase
429 water_(i_aero_phase + i_phase_inst) = &
430 aero_rep(i_aero_rep)%val%spec_state_id( &
439 do i_phase_inst = 1, num_phase
440 water_(i_aero_phase + i_phase_inst) = -1
446 do i_spec = 1, num_react_
450 phase_name = phase_name,
spec_name = react_names(i_spec)%string)
454 "Incorrect instances of reactant '"// &
455 react_names(i_spec)%string//
"' in phase '"//phase_name// &
456 "' in a condensed-phase Photolysis reaction")
461 do i_phase_inst = 1, num_phase
462 react_((i_aero_phase+i_phase_inst-1)*num_react_ + i_spec) = &
463 aero_rep(i_aero_rep)%val%spec_state_id( &
472 do i_spec = 1, num_prod_
476 phase_name = phase_name,
spec_name = prod_names(i_spec)%string)
480 "Incorrect instances of product '"// &
481 prod_names(i_spec)%string//
"' in phase '"//phase_name// &
482 "' in a condensed-phase Photolysis reaction")
487 do i_phase_inst = 1, num_phase
488 prod_((i_aero_phase+i_phase_inst-1)*num_prod_ + i_spec) = &
489 aero_rep(i_aero_rep)%val%spec_state_id( &
498 i_aero_phase = i_aero_phase + num_phase