251 subroutine initialize(this, aero_rep_set, aero_phase_set, chem_spec_data)
262 type(
property_t),
pointer :: spec_props, ion_pairs, ion_pair, sub_props, &
264 character(len=:),
allocatable :: key_name, spec_name, phase_name
265 integer(kind=i_kind) :: n_phase, n_ion_pair, n_int_param, n_float_param, &
266 i_aero_rep, i_phase, i_ion_pair, i_ion, i_spec, i_sub_prop, &
267 qty, int_val, charge, total_charge, tracer_type
268 real(kind=
dp) :: real_val, molecular_weight
269 type(
string_t),
allocatable :: unique_spec_names(:)
270 character(len=:),
allocatable :: str_type, ion_pair_name, ion_name
273 if (.not.
associated(this%property_set))
call die_msg(344693903, &
274 "Missing property set needed to initialize ZSR aerosol water"// &
278 key_name =
"aerosol phase"
280 this%property_set%get_string(key_name, phase_name), &
281 "Missing aerosol phase in ZSR aerosol water reaction.")
285 do i_aero_rep = 1,
size(aero_rep_set)
288 n_phase = n_phase + &
289 aero_rep_set(i_aero_rep)%val%num_phase_instances(phase_name)
294 "Aerosol phase '"//phase_name//
"' not present in any aerosol "// &
295 "representation for ZSR aerosol water reaction.")
298 key_name =
"ion pairs"
300 this%property_set%get_property_t(key_name, ion_pairs), &
301 "Missing ion pairs in ZSR aerosol water reaction.")
304 n_ion_pair = ion_pairs%size()
305 call assert_msg(743158990, n_ion_pair .gt. 0, &
306 "Empty ion pair set in ZSR aerosol water reaction.")
309 n_int_param = num_int_prop_ + n_phase + 2*n_ion_pair
310 n_float_param = num_real_prop_
311 call ion_pairs%iter_reset()
312 do i_ion_pair = 1, n_ion_pair
315 call assert(476976534, ion_pairs%get_key(ion_pair_name))
318 call assert_msg(280814432, ion_pairs%get_property_t(val=ion_pair), &
319 "Missing ion pair properties for '"//ion_pair_name// &
320 "' in ZSR aerosol water reaction.")
324 call assert_msg(334930304, ion_pair%get_string(key_name, str_type), &
325 "Missing activity calculation type for ion pair '"// &
326 ion_pair_name//
"' in ZSR aerosol water reaction.")
329 if (str_type.eq.
"JACOBSON")
then
334 ion_pair%get_property_t(key_name, sub_props), &
335 "Missing Y_j parameters for Jacobson activity calculation "//&
336 "for ion pair '"//ion_pair_name//
"'.")
338 call assert_msg(495036486, sub_props%size().gt.0, &
339 "Insufficient Y_j parameters for Jacobson activity "// &
340 "calculation for ion pair '"//ion_pair_name//
"' in "// &
341 "ZSR aerosol water reaction.")
343 n_float_param = n_float_param + 3 + sub_props%size()
344 n_int_param = n_int_param + 6 + 3*n_phase
346 else if (str_type.eq.
"EQSAM")
then
351 ion_pair%get_property_t(key_name, sub_props), &
352 "Mission ions for EQSAM activity calculation for ion "// &
353 "pair '"//ion_pair_name//
"' in ZSR aerosol water "// &
356 call assert_msg(849524804, sub_props%size().gt.0, &
357 "Insufficient ions specified for EQSAM activity "// &
358 "calculation for ion pair '"//ion_pair_name// &
359 "' in ZSR aerosol water reaction.")
361 n_float_param = n_float_param + 3 + sub_props%size()
362 n_int_param = n_int_param + 2 + n_phase + (1+n_phase)*sub_props%size()
365 call die_msg(704759248,
"Invalid activity type specified for ZSR "// &
366 "aerosol water reaction: '"//str_type//
"'")
369 call ion_pairs%iter_next()
374 allocate(this%condensed_data_int(n_int_param))
375 allocate(this%condensed_data_real(n_float_param))
376 this%condensed_data_int(:) = int(0, kind=
i_kind)
377 this%condensed_data_real(:) = real(0.0, kind=
dp)
380 this%num_env_params = num_env_param_
384 num_ion_pair_ = n_ion_pair
385 total_int_param_ = n_int_param
386 total_float_param_ = n_float_param
389 key_name =
"gas-phase water"
391 this%property_set%get_string(key_name,
spec_name), &
392 "Missing gas-phase water species name in ZSR aerosol water "// &
395 gas_water_id_ = chem_spec_data%gas_state_id(
spec_name)
397 call assert_msg(709909577, gas_water_id_ .gt. 0, &
398 "Cannot find gas-phase water species '"//
spec_name//
"' for "// &
399 "ZSR aerosol water reaction.")
402 key_name =
"aerosol-phase water"
404 this%property_set%get_string(key_name,
spec_name), &
405 "Missing aerosol-phase water species name in ZSR aerosol "// &
410 chem_spec_data%get_type(
spec_name, tracer_type))
412 "ZSR calculated species "//trim(
spec_name)// &
413 " must be of tracer type CONSTANT")
419 do i_aero_rep = 1,
size(aero_rep_set)
420 unique_spec_names = aero_rep_set(i_aero_rep)%val%unique_names( &
422 if (.not.
allocated(unique_spec_names)) cycle
423 do i_spec = 1,
size(unique_spec_names)
424 phase_id_(i_phase) = aero_rep_set(i_aero_rep)%val%spec_state_id( &
425 unique_spec_names(i_spec)%string)
426 call assert(204327668, phase_id_(i_phase).gt.0)
427 i_phase = i_phase + 1
429 deallocate(unique_spec_names)
431 i_phase = i_phase - 1
432 call assert_msg(418435744, i_phase.eq.num_phase_, &
433 "Incorrect number of aerosol water instances in ZSR aerosol "// &
434 "water reaction. Expected "//trim(
to_string(num_phase_))// &
438 n_int_param = num_int_prop_ + num_phase_ + 2*num_ion_pair_
439 n_float_param = num_real_prop_
440 call ion_pairs%iter_reset()
441 do i_ion_pair = 1, n_ion_pair
444 call assert(476976534, ion_pairs%get_key(ion_pair_name))
447 call assert(660267400, ion_pairs%get_property_t(val=ion_pair))
451 pair_int_param_loc_(i_ion_pair) = n_int_param + 1
452 pair_float_param_loc_(i_ion_pair) = n_float_param + 1
456 call assert(288245799, ion_pair%get_string(key_name, str_type))
459 if (str_type.eq.
"JACOBSON")
then
462 type_(i_ion_pair) = act_calc_jacobson
466 call assert(227500762, ion_pair%get_property_t(key_name, sub_props))
467 jacob_num_y_(i_ion_pair) = sub_props%size()
468 call sub_props%iter_reset()
469 do i_sub_prop = 1, sub_props%size()
470 call assert_msg(149509565, sub_props%get_real(val=real_val), &
471 "Invalid Y parameter for ion pair '"// &
472 ion_pair_name//
"' in ZSR aerosol water reaction.")
473 jacob_y_(i_ion_pair, i_sub_prop) = real_val
474 call sub_props%iter_next()
479 call assert_msg(462500894, ion_pair%get_real(key_name, real_val), &
480 "Missing 'low RH' value for ion pair '"// &
481 ion_pair_name//
"' in ZSR aerosol water reaction.")
482 jacob_low_rh_(i_ion_pair) = real_val
485 molecular_weight = 0.0
487 call assert_msg(661006818, ion_pair%get_property_t(key_name, ions), &
488 "Mission ions for Jacobson activity calculation for ion "// &
489 "pair '"//ion_pair_name//
"' in ZSR aerosol water "// &
491 call assert_msg(880831496, ions%size().eq.2, &
492 "Invalid number of unique ions specified for ion pair '"// &
493 ion_pair_name//
"' in for Jacobson activity "// &
494 "calculation in ZSR aerosol water reaction. Expected 2 "// &
496 call ions%iter_reset()
501 call assert(849711956, ions%get_key(ion_name))
505 if (ions%get_property_t(val=sub_props))
then
507 if (sub_props%get_int(key_name, int_val)) qty = int_val
512 chem_spec_data%get_property_set(ion_name, spec_props), &
513 "Missing species properties for ion '"//ion_name// &
514 "' in ZSR aerosol water reaction.")
517 key_name =
"molecular weight [kg mol-1]"
519 spec_props%get_real(key_name, molecular_weight), &
520 "Missing molecular weight for ion '"//ion_name// &
521 "' in ZSR aerosol water reaction.")
525 call assert_msg(310667885, spec_props%get_int(key_name, charge), &
526 "Missing charge for ion '"//ion_name//
"' in ZSR "// &
527 "aerosol water reaction.")
529 if (charge.gt.0)
then
530 jacob_num_cation_(i_ion_pair) = qty
531 jacob_cation_mw_(i_ion_pair) = molecular_weight
532 else if (charge.lt.0)
then
533 jacob_num_anion_(i_ion_pair) = qty
534 jacob_anion_mw_(i_ion_pair) = molecular_weight
536 call die_msg(899416917,
"Neutral species '"//ion_name// &
537 "' not allowed in ZSR aerosol water reaction ion pair")
541 total_charge = total_charge + qty * charge
545 do i_aero_rep = 1,
size(aero_rep_set)
546 unique_spec_names = aero_rep_set(i_aero_rep)%val%unique_names( &
547 phase_name = phase_name,
spec_name = ion_name)
548 if (.not.
allocated(unique_spec_names)) cycle
549 do i_spec = 1,
size(unique_spec_names)
550 if (charge.gt.0)
then
551 if (i_phase.eq.1)
then
552 jacob_cation_id_(i_ion_pair) = &
553 aero_rep_set(i_aero_rep)%val%spec_state_id( &
554 unique_spec_names(i_spec)%string) - &
557 call assert(473680545, jacob_cation_id_(i_ion_pair).eq. &
558 aero_rep_set(i_aero_rep)%val%spec_state_id( &
559 unique_spec_names(i_spec)%string) - &
563 if (i_phase.eq.1)
then
564 jacob_anion_id_(i_ion_pair) = &
565 aero_rep_set(i_aero_rep)%val%spec_state_id( &
566 unique_spec_names(i_spec)%string) - &
569 call assert(234155524, jacob_anion_id_(i_ion_pair).eq. &
570 aero_rep_set(i_aero_rep)%val%spec_state_id( &
571 unique_spec_names(i_spec)%string) - &
575 i_phase = i_phase + 1
577 deallocate(unique_spec_names)
579 i_phase = i_phase - 1
580 call assert_msg(623684811, i_phase.eq.num_phase_, &
581 "Incorrect number of instances of ion species '"// &
582 ion_name//
"' in ZSR aerosol water reaction. Expected "// &
583 trim(
to_string(num_phase_))//
" but got "// &
587 call ions%iter_next()
591 call assert_msg(319151390, total_charge.eq.0, &
592 "Charge imbalance for ion pair '"//ion_pair_name// &
593 " in ZSR aerosol water reaction. Total charge: "// &
596 n_float_param = n_float_param + 3 + jacob_num_y_(i_ion_pair)
597 n_int_param = n_int_param + 6 + 3*n_phase
599 else if (str_type.eq.
"EQSAM")
then
602 type_(i_ion_pair) = act_calc_eqsam
607 ion_pair%get_real(key_name, eqsam_nw_(i_ion_pair)), &
608 "Missing parameter NW for ion pair '"//ion_pair_name// &
609 "' in ZSR aerosol water reaction.")
613 ion_pair%get_real(key_name, eqsam_zw_(i_ion_pair)), &
614 "Missing parameter ZW for ion pair '"//ion_pair_name// &
615 "' in ZSR aerosol water reaction.")
619 ion_pair%get_real(key_name, eqsam_ion_pair_mw_(i_ion_pair)), &
620 "Missing parameter MW for ion pair '"//ion_pair_name// &
621 "' in ZSR aerosol water reaction.")
625 call assert(381088140, ion_pair%get_property_t(key_name, ions))
626 eqsam_num_ion_(i_ion_pair) = ions%size()
627 call ions%iter_reset()
628 do i_ion = 1, ions%size()
631 call assert(849711956, ions%get_key(ion_name))
635 chem_spec_data%get_property_set(ion_name, spec_props), &
636 "Missing species properties for ion '"//ion_name// &
637 "' in ZSR aerosol water reaction.")
640 key_name =
"molecular weight [kg mol-1]"
642 spec_props%get_real(key_name, molecular_weight), &
643 "Missing molecular weight for ion '"//ion_name// &
644 "' in ZSR aerosol water reaction.")
645 eqsam_ion_mw_(i_ion_pair, i_ion) = molecular_weight
649 do i_aero_rep = 1,
size(aero_rep_set)
650 unique_spec_names = aero_rep_set(i_aero_rep)%val%unique_names( &
651 phase_name = phase_name,
spec_name = ion_name)
652 if (.not.
allocated(unique_spec_names)) cycle
653 do i_spec = 1,
size(unique_spec_names)
654 if (i_phase.eq.1)
then
655 eqsam_ion_id_(i_ion_pair,i_ion) = &
656 aero_rep_set(i_aero_rep)%val%spec_state_id( &
657 unique_spec_names(i_spec)%string) - &
660 call assert(973648240, eqsam_ion_id_(i_ion_pair,i_ion) .eq. &
661 aero_rep_set(i_aero_rep)%val%spec_state_id( &
662 unique_spec_names(i_spec)%string) - &
665 i_phase = i_phase + 1
667 deallocate(unique_spec_names)
669 i_phase = i_phase - 1
670 call assert_msg(900921350, i_phase.eq.num_phase_, &
671 "Incorrect number of instances of ion species '"// &
672 ion_name//
"' in ZSR aerosol water reaction. Expected "// &
673 trim(
to_string(num_phase_))//
" but got "// &
677 call ions%iter_next()
681 n_float_param = n_float_param + 3 + eqsam_num_ion_(i_ion_pair)
682 n_int_param = n_int_param + 2 + num_phase_ + &
683 (1+num_phase_)*eqsam_num_ion_(i_ion_pair)
686 call die_msg(186680407,
"Internal error.")
689 call ion_pairs%iter_next()
692 call assert(859412771, n_int_param.eq.total_int_param_)
693 call assert(568314442, n_float_param.eq.total_float_param_)