15 use camp_rxn_photolysis
24 public :: photolysis_t
30 type(camp_core_t),
pointer :: camp_core => null()
32 real(kind=
dp),
allocatable :: base_rates(:)
34 type(rxn_update_data_photolysis_t),
allocatable :: photo_rxns(:)
37 procedure :: update_rate_constants
39 procedure :: pack_size
43 procedure :: bin_unpack
45 procedure :: print => do_print
49 interface photolysis_t
50 procedure :: constructor
51 end interface photolysis_t
58 function constructor(camp_core)
result(new_obj)
61 type(photolysis_t),
pointer :: new_obj
63 type(camp_core_t),
pointer,
intent(in),
optional :: camp_core
65 character(len=:),
allocatable :: rxn_key, rxn_val, rate_key, str_val
66 real(kind=
dp) :: rate_val
67 integer :: i_mech, i_rxn, i_photo_rxn, n_photo_rxns
68 class(rxn_data_t),
pointer :: rxn
73 if (.not.
present(camp_core))
return
77 rxn_val =
"PHOTOLYSIS"
78 rate_key =
"base rate"
80 call assert(254347663,
associated(camp_core))
81 call assert(689045432, camp_core%is_initialized())
82 call assert(256253197,
associated(camp_core%mechanism))
85 new_obj%camp_core => camp_core
89 do i_mech = 1,
size(camp_core%mechanism)
90 do i_rxn = 1, camp_core%mechanism(i_mech)%val%size()
91 rxn => camp_core%mechanism(i_mech)%val%get_rxn(i_rxn)
92 call assert(106297725, rxn%property_set%get_string(rxn_key, str_val))
93 if (trim(str_val) == rxn_val) n_photo_rxns = n_photo_rxns + 1
100 allocate(new_obj%photo_rxns(n_photo_rxns))
101 allocate(new_obj%base_rates(n_photo_rxns))
102 do i_mech = 1,
size(camp_core%mechanism)
105 do i_rxn = 1, camp_core%mechanism(i_mech)%val%size()
106 rxn => camp_core%mechanism(i_mech)%val%get_rxn(i_rxn)
107 call assert(799145523, rxn%property_set%get_string(rxn_key, str_val))
110 if (trim(str_val) /= rxn_val) cycle
111 i_photo_rxn = i_photo_rxn + 1
115 rxn%property_set%get_real(rate_key, rate_val), &
116 "Missing 'base rate' for photolysis reaction "// &
118 new_obj%base_rates(i_photo_rxn) = rate_val
121 select type (rxn_photo => rxn)
122 class is (rxn_photolysis_t)
123 call camp_core%initialize_update_object(rxn_photo, &
124 new_obj%photo_rxns(i_photo_rxn))
131 end function constructor
136 subroutine update_rate_constants(this)
139 class(photolysis_t),
intent(inout) :: this
144 do i_rxn = 1,
size(this%photo_rxns)
145 call this%photo_rxns(i_rxn)%set_rate(this%base_rates(i_rxn))
146 call this%camp_core%update_data(this%photo_rxns(i_rxn))
149 end subroutine update_rate_constants
154 integer function pack_size(this)
159 class(photolysis_t),
intent(in) :: this
165 call assert(127027009,
allocated(this%base_rates))
166 call assert(634138948,
allocated(this%photo_rxns))
172 do i_rxn = 1,
size(this%photo_rxns)
173 pack_size = pack_size + this%photo_rxns(i_rxn)%pack_size()
179 end function pack_size
184 subroutine bin_pack(this, buffer, pos)
189 class(photolysis_t),
intent(in) :: this
191 character,
intent(inout) :: buffer(:)
193 integer,
intent(inout) :: pos
196 integer :: i_rxn, prev_position
198 call assert(971093983,
allocated(this%base_rates))
199 call assert(913255424,
allocated(this%photo_rxns))
204 do i_rxn = 1,
size(this%photo_rxns)
205 call this%photo_rxns(i_rxn)%bin_pack(buffer, pos)
207 call assert(234533342, pos - prev_position <= this%pack_size())
210 end subroutine bin_pack
215 subroutine bin_unpack(this, buffer, pos)
220 class(photolysis_t),
intent(out) :: this
222 character,
intent(inout) :: buffer(:)
224 integer,
intent(inout) :: pos
227 integer :: i_rxn, n_rxns, prev_position
232 allocate(this%photo_rxns(n_rxns))
233 do i_rxn = 1,
size(this%photo_rxns)
234 call this%photo_rxns(i_rxn)%bin_unpack(buffer, pos)
236 call assert(391255154, pos - prev_position <= this%pack_size())
239 end subroutine bin_unpack
244 subroutine do_print(this, file_unit)
247 class(photolysis_t),
intent(in) :: this
249 integer,
optional :: file_unit
251 integer :: f_unit, i_rxn
254 if (
present(file_unit)) f_unit = file_unit
256 write(f_unit,*)
"***************************"
257 write(f_unit,*)
"*** Photolysis Data ***"
258 write(f_unit,*)
"***************************"
260 if (
allocated(this%base_rates))
then
261 do i_rxn = 1,
size(this%base_rates)
262 write(f_unit,*)
" photo rxn(",i_rxn,
") = ", this%base_rates(i_rxn)
265 write(f_unit,*)
" No photolysis data"
268 write(f_unit,*)
"***************************"
269 write(f_unit,*)
"*** End Photolysis Data ***"
270 write(f_unit,*)
"***************************"
272 end subroutine do_print