16#define NUM_REACT_ int_data[0]
17#define NUM_PROD_ int_data[1]
18#define NUM_AERO_PHASE_ int_data[2]
19#define RXN_ID_ int_data[3]
20#define SCALING_ float_data[0]
21#define RATE_CONSTANT_ rxn_env_data[0]
22#define BASE_RATE_ rxn_env_data[1]
23#define NUM_INT_PROP_ 4
24#define NUM_FLOAT_PROP_ 1
25#define NUM_ENV_PARAM_ 2
26#define REACT_(x) (int_data[NUM_INT_PROP_ + x] - 1)
28 (int_data[NUM_INT_PROP_ + NUM_REACT_ * NUM_AERO_PHASE_ + x] - 1)
30 (int_data[NUM_INT_PROP_ + (NUM_REACT_ + NUM_PROD_) * NUM_AERO_PHASE_ + x] - 1)
32 (int_data[NUM_INT_PROP_ + (NUM_REACT_ + NUM_PROD_ + 1) * NUM_AERO_PHASE_ + x])
34 (int_data[NUM_INT_PROP_ + \
35 (2 * (NUM_REACT_ + NUM_PROD_) + 1) * NUM_AERO_PHASE_ + x])
36#define YIELD_(x) (float_data[NUM_FLOAT_PROP_ + x])
37#define KGM3_TO_MOLM3_(x) (float_data[NUM_FLOAT_PROP_ + NUM_PROD_ + x])
46 double *rxn_float_data,
48 int *int_data = rxn_int_data;
49 double *float_data = rxn_float_data;
55 i_react_ind < (i_phase + 1) *
NUM_REACT_; i_react_ind++) {
57 i_react_dep < (i_phase + 1) *
NUM_REACT_; i_react_dep++)
60 for (
int i_prod_dep = i_phase *
NUM_PROD_;
61 i_prod_dep < (i_phase + 1) *
NUM_PROD_; i_prod_dep++)
67 if (
WATER_(i_phase) >= 0) {
69 i_react_dep < (i_phase + 1) *
NUM_REACT_; i_react_dep++)
71 for (
int i_prod_dep = i_phase *
NUM_PROD_;
72 i_prod_dep < (i_phase + 1) *
NUM_PROD_; i_prod_dep++)
91 double *rxn_float_data) {
92 int *int_data = rxn_int_data;
93 double *float_data = rxn_float_data;
96 for (
int i_phase = 0, i_deriv = 0; i_phase <
NUM_AERO_PHASE_; i_phase++) {
97 for (
int i_react = 0; i_react <
NUM_REACT_; i_react++)
99 for (
int i_prod = 0; i_prod <
NUM_PROD_; i_prod++)
104 for (
int i_phase = 0, i_jac = 0; i_phase <
NUM_AERO_PHASE_; i_phase++) {
107 i_react_ind < (i_phase + 1) *
NUM_REACT_; i_react_ind++) {
109 i_react_dep < (i_phase + 1) *
NUM_REACT_; i_react_dep++)
112 for (
int i_prod_dep = i_phase *
NUM_PROD_;
113 i_prod_dep < (i_phase + 1) *
NUM_PROD_; i_prod_dep++)
120 i_react_dep < (i_phase + 1) *
NUM_REACT_; i_react_dep++)
121 if (
WATER_(i_phase) >= 0) {
127 for (
int i_prod_dep = i_phase *
NUM_PROD_;
128 i_prod_dep < (i_phase + 1) *
NUM_PROD_; i_prod_dep++)
129 if (
WATER_(i_phase) >= 0) {
158 double *rxn_float_data,
double *rxn_env_data) {
159 int *int_data = rxn_int_data;
160 double *float_data = rxn_float_data;
162 int *photo_id = (
int *)update_data;
163 double *base_rate = (
double *)&(photo_id[1]);
187 double *rxn_float_data,
188 double *rxn_env_data) {
202#ifdef CAMP_USE_SUNDIALS
205 double *rxn_float_data,
double *rxn_env_data,
double time_step) {
206 int *int_data = rxn_int_data;
207 double *float_data = rxn_float_data;
212 for (
int i_phase = 0, i_deriv = 0; i_phase <
NUM_AERO_PHASE_; i_phase++) {
214 long double unit_conv = 1.0;
215 if (
WATER_(i_phase) >= 0) {
216 unit_conv = state[
WATER_(i_phase)];
220 if (unit_conv <=
ZERO) {
224 unit_conv = 1.0 / unit_conv;
229 for (
int i_react = 0; i_react <
NUM_REACT_; i_react++) {
235 for (
int i_react = 0; i_react <
NUM_REACT_; i_react++) {
245 for (
int i_prod = 0; i_prod <
NUM_PROD_; i_prod++) {
270#ifdef CAMP_USE_SUNDIALS
273 double *rxn_float_data,
double *rxn_env_data,
double time_step) {
274 int *int_data = rxn_int_data;
275 double *float_data = rxn_float_data;
280 for (
int i_phase = 0, i_jac = 0; i_phase <
NUM_AERO_PHASE_; i_phase++) {
282 realtype unit_conv = 1.0;
283 if (
WATER_(i_phase) >= 0) {
284 unit_conv = state[
WATER_(i_phase)];
288 if (unit_conv <=
ZERO) {
292 unit_conv = 1.0 / unit_conv;
296 for (
int i_react_ind = 0; i_react_ind <
NUM_REACT_; i_react_ind++) {
299 for (
int i_react = 0; i_react <
NUM_REACT_; i_react++) {
300 if (i_react == i_react_ind) {
311 for (
int i_react_dep = 0; i_react_dep <
NUM_REACT_; i_react_dep++) {
320 for (
int i_prod_dep = 0; i_prod_dep <
NUM_PROD_; i_prod_dep++) {
327 rate *
YIELD_(i_prod_dep) /
334 if (
WATER_(i_phase) < 0) {
341 for (
int i_react = 0; i_react <
NUM_REACT_; i_react++) {
347 for (
int i_react_dep = 0; i_react_dep <
NUM_REACT_; i_react_dep++) {
357 for (
int i_prod_dep = 0; i_prod_dep <
NUM_PROD_; i_prod_dep++) {
379 double *rxn_float_data) {
380 int *int_data = rxn_int_data;
381 double *float_data = rxn_float_data;
385 printf(
"\n\nCondensed Phase photolysis reaction\n");
387 printf(
"\n number of reactants: %d",
NUM_REACT_);
388 printf(
"\n number of products: %d",
NUM_PROD_);
390 printf(
"\n water state ids (by phase):");
392 printf(
" %d",
WATER_(i_phase));
393 printf(
"\n *** Reactants ***");
394 for (
int i_react = 0; i_react <
NUM_REACT_; ++i_react) {
395 printf(
"\n reactant %d", i_react);
397 printf(
"\n state id (by phase):");
400 printf(
"\n deriv id (by phase):");
404 printf(
"\n *** Products ***");
405 for (
int i_prod = 0; i_prod <
NUM_PROD_; ++i_prod) {
406 printf(
"\n product %d", i_prod);
408 printf(
"\n yield: %le",
YIELD_(i_prod));
409 printf(
"\n state id (by phase):");
412 printf(
"\n deriv id (by phase):");
417 printf(
"\n *** Jac Ids (by phase) ***");
418 for (
int i_ind = 0; i_ind <
NUM_REACT_; ++i_ind) {
419 for (
int i_react = 0; i_react <
NUM_REACT_; ++i_react) {
424 JAC_ID_(i_phase * phase_jac_size +
428 for (
int i_prod = 0; i_prod <
NUM_PROD_; ++i_prod) {
433 JAC_ID_(i_phase * phase_jac_size +
438 for (
int i_react = 0; i_react <
NUM_REACT_; ++i_react) {
443 JAC_ID_(i_phase * phase_jac_size +
447 for (
int i_prod = 0; i_prod <
NUM_PROD_; ++i_prod) {
453 JAC_ID_(i_phase * phase_jac_size +
465 int *update_data = (
int *)malloc(
sizeof(
int) +
sizeof(double));
466 if (update_data == NULL) {
467 printf(
"\n\nERROR allocating space for condensded phase photolysis update data\n\n");
470 return (
void *)update_data;
481 int *new_photo_id = (
int *)update_data;
482 double *new_base_rate = (
double *)&(new_photo_id[1]);
483 *new_photo_id = photo_id;
484 *new_base_rate = base_rate;
unsigned int jacobian_get_element_id(Jacobian jac, unsigned int dep_id, unsigned int ind_id)
Get an element id in the Jacobian data arrays.
void jacobian_add_value(Jacobian jac, unsigned int elem_id, unsigned int prod_or_loss, long double jac_contribution)
Add a contribution to the Jacobian.
void jacobian_register_element(Jacobian *jac, unsigned int dep_id, unsigned int ind_id)
Adds an element to the sparse matrix.
#define JACOBIAN_PRODUCTION
void * rxn_condensed_phase_photolysis_create_rate_update_data()
Create update data for new photolysis rates.
#define KGM3_TO_MOLM3_(x)
void rxn_condensed_phase_photolysis_print(int *rxn_int_data, double *rxn_float_data)
Print the Condensed Phase photolysis reaction parameters.
void rxn_condensed_phase_photolysis_calc_deriv_contrib(ModelData *model_data, TimeDerivative time_deriv, int *rxn_int_data, double *rxn_float_data, double *rxn_env_data, double time_step)
Calculate contributions to the time derivative f(t,y) from this reaction.
void rxn_condensed_phase_photolysis_update_env_state(ModelData *model_data, int *rxn_int_data, double *rxn_float_data, double *rxn_env_data)
Update reaction data for new environmental conditions.
void rxn_condensed_phase_photolysis_set_rate_update_data(void *update_data, int photo_id, double base_rate)
Set rate update data.
void rxn_condensed_phase_photolysis_get_used_jac_elem(int *rxn_int_data, double *rxn_float_data, Jacobian *jac)
Flag Jacobian elements used by this reaction.
void rxn_condensed_phase_photolysis_update_ids(ModelData *model_data, int *deriv_ids, Jacobian jac, int *rxn_int_data, double *rxn_float_data)
Update the time derivative and Jacbobian array indices.
void rxn_condensed_phase_photolysis_calc_jac_contrib(ModelData *model_data, Jacobian jac, int *rxn_int_data, double *rxn_float_data, double *rxn_env_data, double time_step)
Calculate contributions to the Jacobian from this reaction.
bool rxn_condensed_phase_photolysis_update_data(void *update_data, int *rxn_int_data, double *rxn_float_data, double *rxn_env_data)
Update reaction data.
void time_derivative_add_value(TimeDerivative time_deriv, unsigned int spec_id, long double rate_contribution)
Add a contribution to the time derivative.