17#define TEMPERATURE_K_ env_data[0]
18#define PRESSURE_PA_ env_data[1]
20#define NUM_REACT_ int_data[0]
21#define NUM_PROD_ int_data[1]
22#define RXN_ID_ int_data[2]
23#define SCALING_ float_data[0]
24#define RATE_CONSTANT_ (rxn_env_data[0])
25#define BASE_RATE_ (rxn_env_data[1])
26#define NUM_INT_PROP_ 3
27#define NUM_FLOAT_PROP_ 1
28#define NUM_ENV_PARAM_ 2
29#define REACT_(x) (int_data[NUM_INT_PROP_ + x] - 1)
30#define PROD_(x) (int_data[NUM_INT_PROP_ + NUM_REACT_ + x] - 1)
31#define DERIV_ID_(x) int_data[NUM_INT_PROP_ + NUM_REACT_ + NUM_PROD_ + x]
32#define JAC_ID_(x) int_data[NUM_INT_PROP_ + 2 * (NUM_REACT_ + NUM_PROD_) + x]
33#define YIELD_(x) float_data[NUM_FLOAT_PROP_ + x]
43 int *int_data = rxn_int_data;
44 double *float_data = rxn_float_data;
46 for (
int i_ind = 0; i_ind <
NUM_REACT_; i_ind++) {
47 for (
int i_dep = 0; i_dep <
NUM_REACT_; i_dep++) {
50 for (
int i_dep = 0; i_dep <
NUM_PROD_; i_dep++) {
68 double *rxn_float_data) {
69 int *int_data = rxn_int_data;
70 double *float_data = rxn_float_data;
79 for (
int i_ind = 0; i_ind <
NUM_REACT_; i_ind++) {
80 for (
int i_dep = 0; i_dep <
NUM_REACT_; i_dep++) {
84 for (
int i_dep = 0; i_dep <
NUM_PROD_; i_dep++) {
110 double *rxn_float_data,
double *rxn_env_data) {
111 int *int_data = rxn_int_data;
112 double *float_data = rxn_float_data;
114 int *photo_id = (
int *)update_data;
115 double *base_rate = (
double *)&(photo_id[1]);
138 double *rxn_float_data,
139 double *rxn_env_data) {
140 int *int_data = rxn_int_data;
141 double *float_data = rxn_float_data;
160#ifdef CAMP_USE_SUNDIALS
163 double *rxn_float_data,
double *rxn_env_data, realtype time_step) {
164 int *int_data = rxn_int_data;
165 double *float_data = rxn_float_data;
171 for (
int i_spec = 0; i_spec <
NUM_REACT_; i_spec++)
172 rate *= state[
REACT_(i_spec)];
177 for (
int i_spec = 0; i_spec <
NUM_REACT_; i_spec++, i_dep_var++) {
181 for (
int i_spec = 0; i_spec <
NUM_PROD_; i_spec++, i_dep_var++) {
186 if (-rate *
YIELD_(i_spec) * time_step <= state[
PROD_(i_spec)]) {
206#ifdef CAMP_USE_SUNDIALS
208 int *rxn_int_data,
double *rxn_float_data,
209 double *rxn_env_data, realtype time_step) {
210 int *int_data = rxn_int_data;
211 double *float_data = rxn_float_data;
217 for (
int i_ind = 0; i_ind <
NUM_REACT_; i_ind++) {
220 for (
int i_spec = 0; i_spec <
NUM_REACT_; i_spec++)
221 if (i_spec != i_ind) rate *= state[
REACT_(i_spec)];
223 for (
int i_dep = 0; i_dep <
NUM_REACT_; i_dep++, i_elem++) {
224 if (
JAC_ID_(i_elem) < 0)
continue;
228 for (
int i_dep = 0; i_dep <
NUM_PROD_; i_dep++, i_elem++) {
229 if (
JAC_ID_(i_elem) < 0)
continue;
232 if (-rate * state[
REACT_(i_ind)] *
YIELD_(i_dep) * time_step <=
233 state[
PROD_(i_dep)]) {
250 int *int_data = rxn_int_data;
251 double *float_data = rxn_float_data;
253 printf(
"\n\nPhotolysis reaction\n");
263 int *update_data = (
int *)malloc(
sizeof(
int) +
sizeof(double));
264 if (update_data == NULL) {
265 printf(
"\n\nERROR allocating space for photolysis update data\n\n");
268 return (
void *)update_data;
279 int *new_photo_id = (
int *)update_data;
280 double *new_base_rate = (
double *)&(new_photo_id[1]);
281 *new_photo_id = photo_id;
282 *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_photolysis_calc_jac_contrib(ModelData *model_data, Jacobian jac, int *rxn_int_data, double *rxn_float_data, double *rxn_env_data, realtype time_step)
Calculate contributions to the Jacobian from this reaction.
bool rxn_photolysis_update_data(void *update_data, int *rxn_int_data, double *rxn_float_data, double *rxn_env_data)
Update reaction data.
void rxn_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_photolysis_create_rate_update_data()
Create update data for new photolysis rates.
void rxn_photolysis_calc_deriv_contrib(ModelData *model_data, TimeDerivative time_deriv, int *rxn_int_data, double *rxn_float_data, double *rxn_env_data, realtype time_step)
Calculate contributions to the time derivative from this reaction.
void rxn_photolysis_get_used_jac_elem(int *rxn_int_data, double *rxn_float_data, Jacobian *jac)
Flag Jacobian elements used by this reaction.
void rxn_photolysis_print(int *rxn_int_data, double *rxn_float_data)
Print the Photolysis reaction parameters.
void rxn_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_photolysis_set_rate_update_data(void *update_data, int photo_id, double base_rate)
Set rate update data.
void time_derivative_add_value(TimeDerivative time_deriv, unsigned int spec_id, long double rate_contribution)
Add a contribution to the time derivative.