188 subroutine initialize(this, chem_spec_data, aero_rep, n_cells)
197 integer(kind=i_kind),
intent(in) :: n_cells
199 type(
property_t),
pointer :: spec_props, reactants, products
200 character(len=:),
allocatable :: key_name, spec_name, water_name, &
201 phase_name, temp_string
202 integer(kind=i_kind) :: i_spec, i_phase_inst, i_qty, i_aero_rep, &
203 i_aero_phase, num_spec_per_phase, num_phase, num_react, num_prod
204 type(
string_t),
allocatable :: unique_names(:)
205 type(
string_t),
allocatable :: react_names(:), prod_names(:)
207 integer(kind=i_kind) :: temp_int
208 real(kind=
dp) :: temp_real
209 logical :: is_aqueous
214 call assert_msg(852163263,
associated(this%property_set), &
215 "Missing property set needed to initialize reaction")
218 key_name =
"aerosol phase"
220 this%property_set%get_string(key_name, phase_name), &
221 "Missing aerosol phase in condensed-phase Photolysis reaction")
224 key_name =
"reactants"
226 this%property_set%get_property_t(key_name, reactants), &
227 "Missing reactant species in condensed-phase Photolysis reaction")
230 key_name =
"products"
232 this%property_set%get_property_t(key_name, products), &
233 "Missing product species in condensed-phase Photolysis reaction")
237 call reactants%iter_reset()
241 call assert(428593951, reactants%get_property_t(val=spec_props))
243 if (spec_props%get_int(key_name, temp_int)) &
244 num_react = num_react + temp_int - 1
245 call reactants%iter_next()
246 num_react = num_react + 1
250 call assert_msg(890212987, num_react .eq. 1, &
251 "Too many species in condensed-phase Photolysis reaction. Only one reactant is expected.")
253 num_prod = products%size()
254 num_spec_per_phase = num_prod + num_react
257 call assert_msg(370755392,
associated(aero_rep), &
258 "Missing aerosol representation for condensed-phase "// &
259 "Photolysis reaction")
260 call assert_msg(483073737,
size(aero_rep).gt.0, &
261 "Missing aerosol representation for condensed-phase "// &
262 "Photolysis reaction")
266 do i_aero_rep = 1,
size(aero_rep)
267 num_phase = num_phase + &
268 aero_rep(i_aero_rep)%val%num_phase_instances(phase_name)
272 allocate(this%condensed_data_int(num_int_prop_ + &
273 num_phase * (num_spec_per_phase * (num_react + 3) + 1)))
274 allocate(this%condensed_data_real(num_real_prop_ + &
275 num_spec_per_phase + num_prod))
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_react_ = num_react
285 num_aero_phase_ = num_phase
290 key_name =
"scaling factor"
291 if (.not. this%property_set%get_real(key_name, scaling_))
then
292 scaling_ = real(1.0, kind=
dp)
296 allocate(react_names(num_react_))
297 allocate(prod_names(num_prod_))
300 call reactants%iter_reset()
306 chem_spec_data%get_property_set(
spec_name, spec_props), &
307 "Missing properties required for condensed-phase Photolysis "// &
308 "reaction involving species '"//trim(
spec_name)//
"'")
311 key_name =
"molecular weight [kg mol-1]"
312 call assert_msg(409180731, spec_props%get_real(key_name, temp_real), &
313 "Missing 'molecular weight' for species '"//trim(
spec_name)// &
314 "' in condensed-phase Photolysis reaction.")
317 call assert(186449575, reactants%get_property_t(val=spec_props))
319 if (.not.spec_props%get_int(key_name, temp_int)) temp_int = 1
320 do i_qty = 1, temp_int
327 kgm3_to_molm3_(i_spec) = 1.0/temp_real
332 call reactants%iter_next()
337 call products%iter_reset()
343 chem_spec_data%get_property_set(
spec_name, spec_props), &
344 "Missing properties required for condensed-phase Photolysis "// &
345 "reaction involving species '"//trim(
spec_name)//
"'")
351 key_name =
"molecular weight [kg mol-1]"
352 call assert_msg(504705211, spec_props%get_real(key_name, temp_real), &
353 "Missing 'molecular weight' for species '"//trim(
spec_name)// &
354 "' in condensed phase Photolysis reaction.")
357 kgm3_to_molm3_(num_react_+i_spec) = 1.0/temp_real
360 call assert(846924553, products%get_property_t(val=spec_props))
362 if (spec_props%get_real(key_name, temp_real))
then
363 yield_(i_spec) = temp_real
365 yield_(i_spec) = 1.0d0
372 call products%iter_next()
380 this%property_set%get_string(key_name, temp_string), &
381 "Missing units for condensed-phase Photolysis reaction.")
382 if (trim(temp_string).eq.
"mol m-3")
then
384 key_name =
"aerosol-phase water"
386 .not.this%property_set%get_string(key_name, temp_string), &
387 "Aerosol-phase water specified for non-aqueous condensed-"// &
388 "phase Photolysis reaction. Change units to 'M' or remove "// &
389 "aerosol-phase water")
390 else if (trim(temp_string).eq.
"M")
then
392 key_name =
"aerosol-phase water"
394 this%property_set%get_string(key_name, water_name), &
395 "Missing aerosol-phase water for aqeuous condensed-phase "// &
396 "Photolysis reaction.")
398 call die_msg(161772048,
"Received invalid units for condensed-"// &
399 "phase Photolysis reaction: '"//temp_string//
"'. Valid "// &
400 "units are 'mol m-3' or 'M'.")
405 do i_aero_rep = 1,
size(aero_rep)
408 num_phase = aero_rep(i_aero_rep)%val%num_phase_instances(phase_name)
409 if (num_phase.eq.0) cycle
417 phase_name = phase_name,
spec_name = water_name)
421 "Missing aerosol-phase water species '"//water_name// &
422 "' in phase '"//phase_name//
"' in aqueous condensed-"// &
423 "phase Photolysis reacion.")
426 do i_phase_inst = 1, num_phase
427 water_(i_aero_phase + i_phase_inst) = &
428 aero_rep(i_aero_rep)%val%spec_state_id( &
437 do i_phase_inst = 1, num_phase
438 water_(i_aero_phase + i_phase_inst) = -1
444 do i_spec = 1, num_react_
448 phase_name = phase_name,
spec_name = react_names(i_spec)%string)
452 "Incorrect instances of reactant '"// &
453 react_names(i_spec)%string//
"' in phase '"//phase_name// &
454 "' in a condensed-phase Photolysis reaction")
459 do i_phase_inst = 1, num_phase
460 react_((i_aero_phase+i_phase_inst-1)*num_react_ + i_spec) = &
461 aero_rep(i_aero_rep)%val%spec_state_id( &
470 do i_spec = 1, num_prod_
474 phase_name = phase_name,
spec_name = prod_names(i_spec)%string)
478 "Incorrect instances of product '"// &
479 prod_names(i_spec)%string//
"' in phase '"//phase_name// &
480 "' in a condensed-phase Photolysis reaction")
485 do i_phase_inst = 1, num_phase
486 prod_((i_aero_phase+i_phase_inst-1)*num_prod_ + i_spec) = &
487 aero_rep(i_aero_rep)%val%spec_state_id( &
496 i_aero_phase = i_aero_phase + num_phase