242 subroutine initialize(this, aero_rep_set, aero_phase_set, chem_spec_data)
253 type(
property_t),
pointer :: spec_props, phases
254 type(
property_t),
pointer :: func_groups, func_group
255 type(
property_t),
pointer :: main_groups, main_group
256 type(
property_t),
pointer :: spec_groups, interactions
257 character(len=:),
allocatable :: key_name, phase_name, spec_name
258 character(len=:),
allocatable :: inter_group_name
259 character(len=:),
allocatable :: main_group_name, spec_group_name
260 integer(kind=i_kind) :: i_spec, j_spec, i_phase, i_rep, i_main_group
261 integer(kind=i_kind) :: i_instance, i_inter, i_phase_inst, i_spec_group
262 integer(kind=i_kind) :: i_group, i_inter_group
263 integer(kind=i_kind) :: i_UNIFAC_phase
264 integer(kind=i_kind) :: num_unique_phase, num_group, num_main_group
265 integer(kind=i_kind) :: num_int_data, num_real_data, num_env_data
266 integer(kind=i_kind) :: num_spec_group, curr_spec_id, curr_phase_inst_id
267 integer(kind=i_kind) :: m, n, spec_type
268 integer(kind=i_kind),
allocatable :: num_phase_inst(:)
269 integer(kind=i_kind),
allocatable :: num_phase_spec(:)
270 integer(kind=i_kind),
allocatable :: unique_phase_set_id(:)
271 integer(kind=i_kind),
allocatable :: main_group_id(:)
272 type(
string_t),
allocatable :: phase_names(:)
273 type(
string_t),
allocatable :: main_group_names(:)
274 type(
string_t),
allocatable :: group_names(:)
275 type(
string_t),
allocatable :: unique_names(:)
276 type(
string_t),
allocatable :: spec_names(:)
277 real(kind=dp) :: q_i, r_i
278 real(kind=dp) :: inter_param
279 real(kind=dp),
allocatable :: main_group_interactions(:,:)
280 logical :: found, phase_ids_set
283 call assert_msg(403771584,
associated(this%property_set), &
284 "Missing property set needed to initialize UNIFAC model.")
289 this%property_set%get_property_t(key_name, phases), &
290 "Missing set of aerosol phase names for UNIFAC model.")
291 num_unique_phase = phases%size()
292 call assert_msg(780318074, num_unique_phase.gt.0, &
293 "Received empty list of aerosol phase names for UNIFAC model.")
296 key_name =
"functional groups"
298 this%property_set%get_property_t(key_name, func_groups), &
299 "Missing set of functional groups for UNIFAC model.")
300 num_group = func_groups%size()
302 "Received empty set of functional groups for UNIFAC model.")
305 key_name =
"main groups"
307 this%property_set%get_property_t(key_name, main_groups), &
308 "Missing set of main groups for UNIFAC model.")
309 num_main_group = main_groups%size()
310 call assert_msg(556532380, num_main_group.gt.0, &
311 "Received empty set of main groups for UNIFAC model.")
315 allocate(num_phase_inst(num_unique_phase))
316 allocate(num_phase_spec(num_unique_phase))
317 allocate(unique_phase_set_id(num_unique_phase))
318 allocate(phase_names(num_unique_phase))
319 key_name =
"UNIFAC groups"
320 call phases%iter_reset()
321 do i_unifac_phase = 1, num_unique_phase
322 call assert_msg(112836027, phases%get_string(val = phase_name), &
323 "Received non-string phase name in UNIFAC model.")
324 phase_names(i_unifac_phase)%string = phase_name
326 do i_phase = 1,
size(aero_phase_set)
327 if (aero_phase_set(i_phase)%val%name().eq.phase_name)
then
329 unique_phase_set_id(i_unifac_phase) = i_phase
330 num_phase_spec(i_unifac_phase) = 0
331 spec_names = aero_phase_set(i_phase)%val%get_species_names()
332 do i_spec = 1,
size(spec_names)
334 chem_spec_data%get_property_set( &
335 spec_names(i_spec)%string, spec_props))
336 if (spec_props%get_property_t(key_name, spec_groups))
then
337 num_phase_spec(i_unifac_phase) = &
338 num_phase_spec(i_unifac_phase) + 1
341 deallocate(spec_names)
344 call assert_msg(835247755, found,
"Cannot find aerosol phase '"// &
345 phase_name//
"' for UNIFAC model.")
347 num_phase_inst(i_unifac_phase) = 0
348 do i_rep = 1,
size(aero_rep_set)
349 num_phase_inst(i_unifac_phase) = num_phase_inst(i_unifac_phase) + &
350 aero_rep_set(i_rep)%val%num_phase_instances(phase_name)
352 call assert_msg(187041753, num_phase_inst(i_unifac_phase).gt.0, &
353 "No instances of phase '"//phase_name//
"' for UNIFAC model.")
355 call phases%iter_next()
359 num_int_data = num_int_prop_ &
362 num_real_data = num_real_prop_ &
365 + num_group*num_group
366 num_env_data = num_group &
367 + num_group*num_group
368 do i_unifac_phase = 1, num_unique_phase
369 num_int_data = num_int_data + 2 &
370 + num_phase_inst(i_unifac_phase) &
371 + num_phase_spec(i_unifac_phase) &
372 + num_phase_spec(i_unifac_phase) &
373 + num_phase_inst(i_unifac_phase) * &
374 num_phase_spec(i_unifac_phase) * &
375 num_phase_spec(i_unifac_phase) &
376 + num_phase_spec(i_unifac_phase) * num_group
377 num_real_data = num_real_data &
378 + 5*num_phase_spec(i_unifac_phase)
379 num_env_data = num_env_data &
380 + num_phase_spec(i_unifac_phase) * num_group
384 allocate(this%condensed_data_int(num_int_data))
385 allocate(this%condensed_data_real(num_real_data))
386 this%condensed_data_int(:) = int(999999, kind=i_kind)
387 this%condensed_data_real(:) = real(999999.0, kind=dp)
390 this%num_env_params = num_env_data
393 num_unique_phase_ = num_unique_phase
394 num_group_ = num_group
395 total_int_prop_ =
size(this%condensed_data_int)
396 total_real_prop_ =
size(this%condensed_data_real)
399 num_int_data = num_int_prop_ &
402 num_real_data = num_real_prop_ &
405 + num_group*num_group
406 num_env_data = num_group &
407 + num_group*num_group
408 do i_unifac_phase = 1, num_unique_phase
409 phase_int_loc_(i_unifac_phase) = num_int_data + 1
410 phase_float_loc_(i_unifac_phase) = num_real_data + 1
411 phase_env_loc_(i_unifac_phase) = num_env_data + 1
412 num_int_data = num_int_data + 2 &
413 + num_phase_inst(i_unifac_phase) &
414 + num_phase_spec(i_unifac_phase) &
415 + num_phase_spec(i_unifac_phase) &
416 + num_phase_inst(i_unifac_phase) * &
417 num_phase_spec(i_unifac_phase) * &
418 num_phase_spec(i_unifac_phase) &
419 + num_phase_spec(i_unifac_phase) * num_group
420 num_real_data = num_real_data &
421 + 5*num_phase_spec(i_unifac_phase)
422 num_env_data = num_env_data &
423 + num_phase_spec(i_unifac_phase) * num_group
427 do i_unifac_phase = 1, num_unique_phase_
428 num_spec_(i_unifac_phase) = num_phase_spec(i_unifac_phase)
429 num_phase_instance_(i_unifac_phase) = num_phase_inst(i_unifac_phase)
433 allocate(main_group_names(main_groups%size()))
434 call main_groups%iter_reset()
435 do i_main_group = 1, main_groups%size()
439 main_groups%get_key(main_group_names(i_main_group)%string))
441 call main_groups%iter_next()
445 allocate(main_group_interactions(main_groups%size(), main_groups%size()))
446 main_group_interactions(:,:) = real(0.0, kind=dp)
447 call main_groups%iter_reset()
448 do i_main_group = 1, main_groups%size()
451 call assert_msg(577361652, main_groups%get_property_t(val = main_group), &
452 "Invalid main group '"//main_group_names(i_main_group)%string// &
453 "' in UNIFAC model.")
456 key_name =
"interactions with"
458 main_group%get_property_t(key_name, interactions), &
459 "Missing interactions for main group '"// &
460 main_group_names(i_main_group)%string//
"' in UNIFAC model.")
463 call interactions%iter_reset()
464 do i_inter = 1, interactions%size()
467 call assert(363540699, interactions%get_key(inter_group_name))
470 call assert_msg(976253437, interactions%get_real(val = inter_param), &
471 "Invalid interaction parameter for interaction between "// &
472 "main groups '"//main_group_names(i_main_group)%string// &
473 "' and '"//trim(inter_group_name)//
"' in UNIFAC model.")
476 do i_inter_group = 1,
size(main_group_names)
478 if (main_group_names(i_inter_group)%string .eq. &
479 inter_group_name)
then
480 main_group_interactions(i_main_group, i_inter_group) = inter_param
485 call assert_msg(898262240, found,
"Bad main group name '"// &
486 inter_group_name//
"' in interactions of '"// &
487 main_group_names(i_main_group)%string//
"' in UNIFAC model.")
489 call interactions%iter_next()
492 call main_groups%iter_next()
496 allocate(group_names(num_group_))
497 allocate(main_group_id(num_group_))
498 call func_groups%iter_reset()
499 do i_group = 1, num_group_
502 call assert(803878279, func_groups%get_key(group_names(i_group)%string))
505 call assert_msg(657972204, func_groups%get_property_t(val = func_group), &
506 "Invalid functional group '"//group_names(i_group)%string// &
507 "' in UNIFAC model.")
510 key_name =
"volume param"
512 func_group%get_real(key_name, r_k_(i_group)), &
513 "Missing volume parameter in functional group '"// &
514 group_names(i_group)%string//
"' in UNIFAC model.")
517 key_name =
"surface param"
519 func_group%get_real(key_name, q_k_(i_group)), &
520 "Missing surface parameter in functional group '"// &
521 group_names(i_group)%string//
"' in UNIFAC model.")
524 key_name =
"main group"
526 func_group%get_string(key_name, main_group_name), &
527 "Missing main group name in functional group '"// &
528 group_names(i_group)%string//
"' in UNIFAC model.")
531 do i_main_group = 1, num_main_group
533 if (main_group_names(i_main_group)%string.eq.main_group_name)
then
534 main_group_id(i_group) = i_main_group
539 call assert_msg(752356165, found,
"Missing main group '"// &
540 main_group_name//
"' needed by functional group '"// &
541 group_names(i_group)%string//
"' in UNIFAC model.")
543 call func_groups%iter_next()
549 a_mn_(m,n) = main_group_interactions(main_group_id(m), &
555 do i_unifac_phase = 1, num_unique_phase_
556 phase_name = phase_names(i_unifac_phase)%string
557 i_phase = unique_phase_set_id(i_unifac_phase)
561 phase_ids_set = .false.
562 spec_names = aero_phase_set(i_phase)%val%get_species_names()
563 do i_spec = 1,
size(spec_names)
567 chem_spec_data%get_property_set( &
568 spec_names(i_spec)%string, spec_props))
571 key_name =
"UNIFAC groups"
572 if (spec_props%get_property_t(key_name, spec_groups))
then
573 curr_spec_id = curr_spec_id + 1
576 key_name =
"molecular weight [kg mol-1]"
578 spec_props%get_real(key_name, &
579 mw_i_(i_unifac_phase, curr_spec_id)), &
580 "Missing molecular weight for UNIFAC species '"// &
581 spec_names(i_spec)%string//
"'")
584 call assert_msg(511238330, spec_groups%size().gt.0, &
585 "Received empty set of UNIFAC groups for species '"// &
586 spec_names(i_spec)%string//
"'")
589 do i_group = 1,
size(group_names)
590 v_ik_(i_unifac_phase, curr_spec_id, i_group) = 0
595 call spec_groups%iter_reset()
596 do i_spec_group = 1, spec_groups%size()
599 call assert(649713038, spec_groups%get_key(spec_group_name))
602 call assert_msg(429888360, spec_groups%get_int(val = num_spec_group), &
603 "Received non-integer number of UNIFAC groups for '"// &
604 spec_names(i_spec)%string//
"'")
609 do i_group = 1,
size(group_names)
610 if (group_names(i_group)%string.eq.spec_group_name)
then
612 v_ik_(i_unifac_phase, curr_spec_id,i_group) = num_spec_group
617 "Invalid UNIFAC functional group specified for '"// &
618 spec_names(i_spec)%string//
"'")
622 r_i = real(0.0, kind=dp)
623 q_i = real(0.0, kind=dp)
624 do i_group = 1, num_group_
625 r_i = r_i + r_k_(i_group) &
626 * real(v_ik_(i_unifac_phase ,curr_spec_id, i_group), &
628 q_i = q_i + q_k_(i_group) &
629 * real(v_ik_(i_unifac_phase, curr_spec_id, i_group), &
632 r_i_(i_unifac_phase, curr_spec_id) = r_i
633 q_i_(i_unifac_phase, curr_spec_id) = q_i
636 l_i_(i_unifac_phase, curr_spec_id) = 5.0d0 &
637 * ( r_i - q_i ) - ( r_i - 1.0d0 )
639 call spec_groups%iter_next()
644 if (.not.phase_ids_set)
then
645 curr_phase_inst_id = 0
646 do i_rep = 1,
size(aero_rep_set)
648 phase_name = phase_name, &
651 curr_phase_inst_id = curr_phase_inst_id + 1
652 phase_inst_id_(i_unifac_phase, curr_phase_inst_id) = &
653 aero_rep_set(i_rep)%val%spec_state_id( &
657 spec_id_(i_unifac_phase, curr_spec_id) = 0
658 phase_ids_set = .true.
660 do i_rep = 1,
size(aero_rep_set)
662 phase_name = phase_name, &
665 spec_id_(i_unifac_phase, curr_spec_id) = &
666 aero_rep_set(i_rep)%val%spec_state_id( &
668 phase_inst_id_(i_unifac_phase, 1)
675 key_name =
"chemical species"
677 do j_spec = 1,
size(spec_names)
678 call assert(739328266, chem_spec_data%get_type( &
679 spec_names(j_spec)%string, spec_type))
681 call assert(190005517, chem_spec_data%get_property_set( &
682 spec_names(j_spec)%string, spec_props))
683 if (spec_props%get_string(key_name,
spec_name))
then
684 if (spec_names(i_spec)%string.eq.
spec_name)
then
685 do i_rep = 1,
size(aero_rep_set)
687 phase_name = phase_name, &
690 gamma_id_(i_unifac_phase, curr_spec_id) = &
691 aero_rep_set(i_rep)%val%spec_state_id( &
693 phase_inst_id_(i_unifac_phase, 1)
702 "Missing activity coefficient for "//trim( &
703 spec_names(i_spec)%string))
709 deallocate(num_phase_inst)
710 deallocate(num_phase_spec)
711 deallocate(unique_phase_set_id)
712 deallocate(phase_names)
713 deallocate(main_group_names)
714 deallocate(main_group_interactions)
715 deallocate(group_names)