80#define NUM_REACT_ this%condensed_data_int(1)
81#define NUM_PROD_ this%condensed_data_int(2)
82#define NUM_AERO_PHASE_ this%condensed_data_int(3)
83#define RXN_ID_ this%condensed_data_int(4)
84#define SCALING_ this%condensed_data_real(1)
85#define NUM_REAL_PROP_ 1
86#define NUM_INT_PROP_ 4
87#define NUM_ENV_PARAM_ 2
88#define REACT_(x) this%condensed_data_int(NUM_INT_PROP_+x)
89#define PROD_(x) this%condensed_data_int(NUM_INT_PROP_+NUM_REACT_*NUM_AERO_PHASE_+x)
90#define WATER_(x) this%condensed_data_int(NUM_INT_PROP_+(NUM_REACT_+NUM_PROD_)*NUM_AERO_PHASE_+x)
91#define DERIV_ID_(x) this%condensed_data_int(NUM_INT_PROP_+(NUM_REACT_+NUM_PROD_+1)*NUM_AERO_PHASE_+x)
92#define JAC_ID_(x) this%condensed_data_int(NUM_INT_PROP_+(2*(NUM_REACT_+NUM_PROD_)+1)*NUM_AERO_PHASE_+x)
93#define YIELD_(x) this%condensed_data_real(NUM_REAL_PROP_+x)
94#define KGM3_TO_MOLM3_(x) this%condensed_data_real(NUM_REAL_PROP_+NUM_PROD_+x)
120 logical :: is_malloced = .false.
122 integer(kind=i_kind) :: rxn_unique_id = 0
144 type(c_ptr) :: update_data
152 type(c_ptr),
value :: update_data
154 integer(kind=c_int),
value :: photo_id
156 real(kind=c_double),
value :: base_rate
163 type(c_ptr),
value,
intent(in) :: update_data
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
517 prop_set => this%property_set
529 if (
associated(this%property_set)) &
530 deallocate(this%property_set)
531 if (
allocated(this%condensed_data_real)) &
532 deallocate(this%condensed_data_real)
533 if (
allocated(this%condensed_data_int)) &
534 deallocate(this%condensed_data_int)
546 integer(kind=i_kind) :: i
562 real(kind=
dp),
intent(in) :: base_rate
565 this%rxn_unique_id, base_rate)
581 integer(kind=i_kind),
intent(in) :: rxn_type
584 if (rxn_id_.eq.-1)
then
588 update_data%rxn_unique_id = rxn_id_
589 update_data%rxn_type = int(rxn_type, kind=c_int)
591 update_data%is_malloced = .true.
604 integer,
intent(in) :: comm
620 character,
intent(inout) :: buffer(:)
622 integer,
intent(inout) :: pos
624 integer,
intent(in) :: comm
627 integer :: prev_position
633 pos - prev_position <= this%pack_size(comm))
646 character,
intent(inout) :: buffer(:)
648 integer,
intent(inout) :: pos
650 integer,
intent(in) :: comm
653 integer :: prev_position
659 pos - prev_position <= this%pack_size(comm))
685 integer(kind=i_kind) :: i
Initialize the aerosol representation data, validating component data and loading any required inform...
Extending-type binary pack function (Internal use only)
Extending-type binary unpack function (Internal use only)
Extending-type binary pack size (internal use only)
Get the non-unique name of a chemical species by its unique name.
Get a list of unique names for each element on the camp_camp_state::camp_state_t::state_var array for...
Interface to c reaction functions.
Set a new photolysis rate.
Free an update rate data object.
Interface for to_string functions.
The abstract aero_phase_data_t structure and associated subroutines.
subroutine finalize_array(this)
Finalize the aerosol phase data.
class(property_t) function, pointer get_property_set(this)
Get the aerosol phase property set.
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.
integer(kind=i_kind) function pack_size(this, comm)
Determine the size of a binary required to pack the aerosol representation 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.
Wrapper functions for MPI.
subroutine camp_mpi_pack_logical(buffer, position, val, comm)
Packs the given value into the buffer, advancing position.
subroutine camp_mpi_unpack_integer(buffer, position, val, comm)
Unpacks the given value from the buffer, advancing position.
subroutine camp_mpi_unpack_logical(buffer, position, val, comm)
Unpacks the given value from the buffer, advancing position.
integer function camp_mpi_pack_size_logical(val, comm)
Determines the number of bytes required to pack the given value.
subroutine camp_mpi_pack_integer(buffer, position, val, comm)
Packs the given value into the buffer, advancing position.
integer function camp_mpi_pack_size_integer(val, comm)
Determines the number of bytes required to pack the given value.
The property_t structure and associated subroutines.
Random number generators.
integer(kind=i_kind) function generate_int_id()
Generate an integer id Ids will be sequential, and can only be generated by the primary process.
The rxn_condensed_phase_photolysis_t type and associated functions.
subroutine update_data_finalize_array(this)
Finalize an array of update data objects.
subroutine update_data_initialize(this, update_data, rxn_type)
Initialize update data.
subroutine update_data_finalize(this)
Finalize an update data object.
subroutine update_data_rate_set(this, base_rate)
Set packed update data for photolysis rate constants.
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.
Generic test reaction data type.
Condensed-phase Photolysis rate update object.
Abstract reaction data type.
String type for building arrays of string of various size.