61#define NUM_ADJACENT_PAIRS_ this%condensed_data_int(1)
63#define NUM_INT_PROP_ 1
64#define NUM_REAL_PROP_ 0
65#define NUM_ENV_PARAM_ 0
66#define BLOCK_SIZE_ 1000
68#define DIFF_COEFF_INNER_(x) this%condensed_data_real(NUM_REAL_PROP_ + (x))
69#define DIFF_COEFF_OUTER_(x) this%condensed_data_real(NUM_REAL_PROP_ + NUM_ADJACENT_PAIRS_ + (x))
72#define PHASE_ID_INNER_(x) this%condensed_data_int(NUM_INT_PROP_ + (x))
73#define PHASE_ID_OUTER_(x) this%condensed_data_int(NUM_INT_PROP_ + NUM_ADJACENT_PAIRS_ + (x))
74#define AERO_SPEC_INNER_(x) this%condensed_data_int(NUM_INT_PROP_ + 2*NUM_ADJACENT_PAIRS_ + (x))
75#define AERO_SPEC_OUTER_(x) this%condensed_data_int(NUM_INT_PROP_ + 3*NUM_ADJACENT_PAIRS_ + (x))
76#define AERO_REP_ID_(x) this%condensed_data_int(NUM_INT_PROP_ + 4*NUM_ADJACENT_PAIRS_ + (x))
77#define DERIV_ID_INNER_(x) this%condensed_data_int(NUM_INT_PROP_ + 5*NUM_ADJACENT_PAIRS_ + (x))
78#define DERIV_ID_OUTER_(x) this%condensed_data_int(NUM_INT_PROP_ + 6*NUM_ADJACENT_PAIRS_ + (x))
124 subroutine initialize(this, chem_spec_data, aero_phase, aero_rep, n_cells)
135 integer(kind=i_kind),
intent(in) :: n_cells
139 type(
string_t),
allocatable :: diffusion_phase_names(:)
140 type(
string_t),
allocatable :: diffusion_species_names(:)
141 type(
string_t),
allocatable :: diffusion_species_names_inner(:), diffusion_species_names_outer(:)
142 type(
string_t),
allocatable :: diffusion_phase_names_inner(:), diffusion_phase_names_outer(:)
143 type(
property_t),
pointer :: species, spec_props, spec_property_set, aero_phase_property_set
144 character(len=:),
allocatable :: key_name, error_msg
145 character(len=:),
allocatable :: phase_name, species_name
146 character(len=:),
allocatable :: inner_phase_name, outer_phase_name
147 integer(kind=i_kind) :: num_adjacent_pairs
148 integer(kind=i_kind) :: i_aero_rep, i_aero_id, i, i_adj_rep_id
149 integer(kind=i_kind) :: i_phase, i_species, i_adj_pairs
150 logical :: found_inner_coeff, found_outer_coeff
151 integer(kind=i_kind),
allocatable :: adj_phase_size(:)
153 integer(kind=i_kind),
allocatable :: phase_ids(:)
154 real(kind=
dp) :: temp_real
157 if (.not.
associated(this%property_set))
call die_msg(300992470, &
158 "Missing property set needed to initialize reaction")
163 this%property_set%get_property_t(key_name, species), &
164 "Missing species for condensed phase diffusion "// &
166 call assert_msg(340551815, species%size() .gt. 0, &
167 "No species specified for the condensed phase "// &
168 "diffusion reaction.")
169 call assert_msg(023007260, species%size() .lt. 3, &
170 "Too many species specified for condensed phase "// &
171 "diffusion reaction (two species maximum).")
175 allocate(diffusion_phase_names(species%size()))
176 allocate(diffusion_species_names(species%size()))
178 call species%iter_reset()
179 do i_species = 1, species%size()
182 call assert_msg(815257799, species%get_property_t(val=spec_props), &
183 "Invalid structure for species '"// &
185 "' in condensed phase diffusion reaction.")
189 call assert_msg(354574496, spec_props%get_string(key_name, phase_name), &
190 "Missing phase name in condensed phase diffusion reaction for species entry "// &
192 diffusion_phase_names(i_species)%string = phase_name
196 call assert_msg(629919883, spec_props%get_string(key_name, species_name), &
197 "Missing species name in condensed phase diffusion reaction for species entry "// &
199 diffusion_species_names(i_species)%string = species_name
201 call species%iter_next()
207 if (
allocated(diffusion_species_names))
then
208 if (
size(diffusion_species_names) == 1)
then
209 diffusion_phase_names = [diffusion_phase_names, diffusion_phase_names(1)]
210 diffusion_species_names = [diffusion_species_names, diffusion_species_names(1)]
215 call assert_msg(593348903,
size(diffusion_phase_names) .le. 2, &
216 "Too many diffusing species in diffusion_phase_names array.")
217 call assert_msg(379981970,
size(diffusion_species_names) .le. 2, &
218 "Too many diffusing species in diffusion_species_names array.")
222 allocate(this%condensed_data_int(block_size_ * 20 ))
223 allocate(this%condensed_data_real(block_size_ * 2 ))
224 this%condensed_data_int(:) = int(0, kind=
i_kind)
225 this%condensed_data_real(:) = real(0.0, kind=
dp)
231 allocate(adj_phase_size(
size(aero_rep)))
232 num_adjacent_pairs = 0
233 do i_aero_rep = 1,
size(aero_rep)
234 adjacent_phases = aero_rep(i_aero_rep)%val%adjacent_phases(diffusion_phase_names(1)%string, &
235 diffusion_phase_names(
SIZE(diffusion_phase_names))%string)
239 num_adjacent_pairs_ = num_adjacent_pairs
242 do i_aero_rep = 1,
size(aero_rep)
243 adjacent_phases = aero_rep(i_aero_rep)%val%adjacent_phases(diffusion_phase_names(1)%string, &
244 diffusion_phase_names(
SIZE(diffusion_phase_names))%string)
246 i_adj_pairs = i_adj_pairs + 1
254 allocate(diffusion_phase_names_inner(num_adjacent_pairs))
255 allocate(diffusion_phase_names_outer(num_adjacent_pairs))
256 allocate(diffusion_species_names_inner(num_adjacent_pairs))
257 allocate(diffusion_species_names_outer(num_adjacent_pairs))
258 do i_aero_rep = 1,
size(aero_rep)
259 adjacent_phases = aero_rep(i_aero_rep)%val%adjacent_phases(diffusion_phase_names(1)%string, &
260 diffusion_phase_names(
SIZE(diffusion_phase_names))%string)
262 i_adj_pairs = i_adj_pairs + 1
263 inner_phase_name = aero_rep(i_aero_rep)%val%aero_phase(
adjacent_phases(i)%first_)%val%name()
264 outer_phase_name = aero_rep(i_aero_rep)%val%aero_phase(
adjacent_phases(i)%second_)%val%name()
266 if (inner_phase_name .eq. diffusion_phase_names(1)%string)
then
267 diffusion_species_names_inner(i_adj_pairs) = diffusion_species_names(1)
268 diffusion_phase_names_inner(i_adj_pairs) = diffusion_phase_names(1)
269 else if (inner_phase_name .eq. diffusion_phase_names(
SIZE(diffusion_phase_names))%string)
then
270 diffusion_species_names_inner(i_adj_pairs) = diffusion_species_names(
SIZE(diffusion_species_names))
271 diffusion_phase_names_inner(i_adj_pairs) = diffusion_phase_names(
SIZE(diffusion_phase_names))
273 call die_msg(918766455,
"Could not map inner phase name to diffusing species.")
275 if (outer_phase_name .eq. diffusion_phase_names(1)%string)
then
276 diffusion_species_names_outer(i_adj_pairs) = diffusion_species_names(1)
277 diffusion_phase_names_outer(i_adj_pairs) = diffusion_phase_names(1)
278 else if (outer_phase_name .eq. diffusion_phase_names(
SIZE(diffusion_phase_names))%string)
then
279 diffusion_species_names_outer(i_adj_pairs) = diffusion_species_names(
SIZE(diffusion_species_names))
280 diffusion_phase_names_outer(i_adj_pairs) = diffusion_phase_names(
SIZE(diffusion_phase_names))
282 call die_msg(286189763,
"Could not map outer phase name to diffusing species.")
286 if (i_adj_pairs .ne. num_adjacent_pairs_ .or. &
287 size(diffusion_phase_names_inner) .ne. num_adjacent_pairs_ .or. &
288 size(diffusion_phase_names_outer) .ne. num_adjacent_pairs_ .or. &
289 size(diffusion_species_names_inner) .ne. num_adjacent_pairs_ .or. &
290 size(diffusion_species_names_outer) .ne. num_adjacent_pairs_)
then
291 call die_msg(286189821,
"Mismatch between number of adjacent phase pairs and number of diffusion species.")
295 do i_aero_rep = 1,
size(aero_rep)
296 adjacent_phases = aero_rep(i_aero_rep)%val%adjacent_phases(diffusion_phase_names(1)%string, &
297 diffusion_phase_names(
SIZE(diffusion_phase_names))%string)
299 i_adj_pairs = i_adj_pairs + 1
300 aero_spec_inner_(i_adj_pairs) = aero_rep(i_aero_rep)%val%spec_state_id_by_phase( &
301 adjacent_phases(i)%first_, diffusion_species_names_inner(i_adj_pairs)%string)
302 aero_spec_outer_(i_adj_pairs) = aero_rep(i_aero_rep)%val%spec_state_id_by_phase( &
303 adjacent_phases(i)%second_, diffusion_species_names_outer(i_adj_pairs)%string)
307 call assert_msg(051987857, num_adjacent_pairs .gt. 0, &
308 "No adjacent phases found condensed phase diffusion reaction.")
311 found_inner_coeff = .false.
312 found_outer_coeff = .false.
313 do i_phase = 1,
size(aero_phase)
314 do i_adj_pairs = 1, num_adjacent_pairs
315 if (aero_phase(i_phase)%val%name() .eq. diffusion_phase_names_inner(i_adj_pairs)%string)
then
316 spec_property_set => aero_phase(i_phase)%val%get_spec_property_set( &
317 diffusion_species_names_inner(i_adj_pairs)%string)
318 key_name =
"diffusion coefficient [m2 s-1]"
319 if (spec_property_set%get_real(key_name, temp_real))
then
320 diff_coeff_inner_(i_adj_pairs) = temp_real
321 found_inner_coeff = .true.
324 if (aero_phase(i_phase)%val%name() .eq. diffusion_phase_names_outer(i_adj_pairs)%string)
then
325 spec_property_set => aero_phase(i_phase)%val%get_spec_property_set( &
326 diffusion_species_names_outer(i_adj_pairs)%string)
327 key_name =
"diffusion coefficient [m2 s-1]"
328 if (spec_property_set%get_real(key_name, temp_real))
then
329 diff_coeff_outer_(i_adj_pairs) = temp_real
330 found_outer_coeff = .true.
336 call assert_msg(857293144, found_inner_coeff,
"Missing diffusion coefficient [m2 s-1] for species '"// &
337 diffusion_species_names(1)%string//
"' in phase '"// &
338 diffusion_phase_names(1)%string//
"'.")
339 call assert_msg(857293145, found_outer_coeff,
"Missing diffusion coefficient [m2 s-1] for species '"// &
340 diffusion_species_names(
SIZE(diffusion_species_names))%string//
"' in phase '"// &
341 diffusion_phase_names(
SIZE(diffusion_phase_names))%string//
"'.")
344 error_msg =
" for condensed phase diffusion of aerosol species '"// &
345 diffusion_species_names(1)%string//
"' to aerosol species '"// &
346 diffusion_species_names(
SIZE(diffusion_species_names))%string
349 call assert_msg(161043212,
associated(aero_rep), &
350 "Missing aerosol representation"//error_msg)
351 call assert_msg(411220610,
size(aero_rep).gt.0, &
352 "Missing aerosol representation"//error_msg)
355 this%num_env_params = num_env_param_
360 do i_aero_rep = 1,
size(aero_rep)
361 do i_adj_pairs = 1, adj_phase_size(i_aero_rep)
362 aero_rep_id_(i_adj_rep_id) = i_aero_id
363 i_adj_rep_id = i_adj_rep_id + 1
365 i_aero_id = i_aero_id + 1
368 deallocate(adj_phase_size)
380 if (
associated(this%property_set)) &
381 deallocate(this%property_set)
382 if (
allocated(this%condensed_data_real)) &
383 deallocate(this%condensed_data_real)
384 if (
allocated(this%condensed_data_int)) &
385 deallocate(this%condensed_data_int)
397 integer(kind=i_kind) :: i
Determine if specified phase(s) exist in adjacent layers. Returns array of phase_ids for adjacent pha...
Initialize the aerosol representation data, validating component data and loading any required inform...
Interface for to_string functions.
The abstract aero_phase_data_t structure and associated subroutines.
subroutine finalize_array(this)
Finalize the aerosol phase data.
type(aero_phase_data_t) function, pointer constructor(phase_name, init_size)
Constructor for aero_phase_data_t.
subroutine finalize(this)
Finalize the aerosol phase data.
The abstract aero_rep_data_t structure and associated subroutines.
The camp_state_t structure and associated subroutines.
The chem_spec_data_t structure and associated subroutines.
integer, parameter dp
Kind of a double precision real number.
type(const_t), save const
Fixed variable for accessing the constant's values.
integer, parameter i_kind
Kind of an integer.
The property_t structure and associated subroutines.
The rxn_condensed_phase_diffusion_t type and associated functions.
The rxn_data_t structure and associated subroutines.
integer(kind=i_kind), parameter, public aero_rxn
Aerosol-phase reaction.
Common utility subroutines.
subroutine assert(code, condition_ok)
Errors unless condition_ok is true.
subroutine die_msg(code, error_msg)
Error immediately.
subroutine assert_msg(code, condition_ok, error_msg)
Errors unless condition_ok is true.
Pointer type for building arrays.
Pointer to aero_rep_data_t extending types.
Define index_pair array for adjacent_phases functions.
Generic test reaction data type.
Abstract reaction data type.
String type for building arrays of string of various size.