17#define TEMPERATURE_K_ env_data[0]
18#define PRESSURE_PA_ env_data[1]
21#define SMALL_NUMBER_ 1.0e-30
25#define MIN_WATER_ 1.0e-4
27#define NUM_REACT_ (int_data[0])
28#define NUM_PROD_ (int_data[1])
29#define NUM_AERO_PHASE_ (int_data[2])
30#define A_ (float_data[0])
31#define C_ (float_data[1])
32#define RATE_CONST_REVERSE_ (float_data[2])
33#define WATER_CONC_ (float_data[3])
34#define ACTIVITY_COEFF_VALUE_ (float_data[4])
35#define RATE_CONST_FORWARD_ (rxn_env_data[0])
36#define NUM_INT_PROP_ 3
37#define NUM_FLOAT_PROP_ 5
38#define NUM_ENV_PARAM_ 1
39#define REACT_(x) (int_data[NUM_INT_PROP_ + x] - 1)
41 (int_data[NUM_INT_PROP_ + NUM_REACT_ * NUM_AERO_PHASE_ + x] - 1)
43 (int_data[NUM_INT_PROP_ + (NUM_REACT_ + NUM_PROD_) * NUM_AERO_PHASE_ + x] - 1)
44#define ACTIVITY_COEFF_(x) \
45 (int_data[NUM_INT_PROP_ + (NUM_REACT_ + NUM_PROD_ + 1) * NUM_AERO_PHASE_ + \
49 (int_data[NUM_INT_PROP_ + (NUM_REACT_ + NUM_PROD_ + 2) * NUM_AERO_PHASE_ + x])
51 (int_data[NUM_INT_PROP_ + \
52 (2 * (NUM_REACT_ + NUM_PROD_) + 2) * NUM_AERO_PHASE_ + x])
53#define MASS_FRAC_TO_M_(x) (float_data[NUM_FLOAT_PROP_ + x])
54#define REACT_CONC_(x) \
55 (float_data[NUM_FLOAT_PROP_ + NUM_REACT_ + NUM_PROD_ + x])
56#define PROD_CONC_(x) \
57 (float_data[NUM_FLOAT_PROP_ + 2 * NUM_REACT_ + NUM_PROD_ + x])
58#define SMALL_WATER_CONC_(x) \
59 (float_data[NUM_FLOAT_PROP_ + 2 * NUM_REACT_ + 2 * NUM_PROD_ + x])
60#define SMALL_CONC_(x) \
61 (float_data[NUM_FLOAT_PROP_ + 2 * NUM_REACT_ + 2 * NUM_PROD_ + \
71 double *rxn_float_data,
73 int *int_data = rxn_int_data;
74 double *float_data = rxn_float_data;
80 i_react_ind < (i_phase + 1) *
NUM_REACT_; i_react_ind++) {
82 i_react_dep < (i_phase + 1) *
NUM_REACT_; i_react_dep++)
85 for (
int i_prod_dep = i_phase *
NUM_PROD_;
86 i_prod_dep < (i_phase + 1) *
NUM_PROD_; i_prod_dep++)
91 for (
int i_prod_ind = i_phase *
NUM_PROD_;
92 i_prod_ind < (i_phase + 1) *
NUM_PROD_; i_prod_ind++) {
94 i_react_dep < (i_phase + 1) *
NUM_REACT_; i_react_dep++)
96 for (
int i_prod_dep = i_phase *
NUM_PROD_;
97 i_prod_dep < (i_phase + 1) *
NUM_PROD_; i_prod_dep++)
103 i_react_dep < (i_phase + 1) *
NUM_REACT_; i_react_dep++)
105 for (
int i_prod_dep = i_phase *
NUM_PROD_;
106 i_prod_dep < (i_phase + 1) *
NUM_PROD_; i_prod_dep++)
112 i_react_dep < (i_phase + 1) *
NUM_REACT_; ++i_react_dep)
115 for (
int i_prod_dep = i_phase *
NUM_PROD_;
116 i_prod_dep < (i_phase + 1) *
NUM_PROD_; ++i_prod_dep)
134 double *rxn_float_data) {
135 int *int_data = rxn_int_data;
136 double *float_data = rxn_float_data;
139 for (
int i_phase = 0, i_deriv = 0; i_phase <
NUM_AERO_PHASE_; i_phase++) {
140 for (
int i_react = 0; i_react <
NUM_REACT_; i_react++)
142 for (
int i_prod = 0; i_prod <
NUM_PROD_; i_prod++)
147 for (
int i_phase = 0, i_jac = 0; i_phase <
NUM_AERO_PHASE_; i_phase++) {
150 i_react_ind < (i_phase + 1) *
NUM_REACT_; i_react_ind++) {
152 i_react_dep < (i_phase + 1) *
NUM_REACT_; i_react_dep++)
155 for (
int i_prod_dep = i_phase *
NUM_PROD_;
156 i_prod_dep < (i_phase + 1) *
NUM_PROD_; i_prod_dep++)
162 for (
int i_prod_ind = i_phase *
NUM_PROD_;
163 i_prod_ind < (i_phase + 1) *
NUM_PROD_; i_prod_ind++) {
165 i_react_dep < (i_phase + 1) *
NUM_REACT_; i_react_dep++)
168 for (
int i_prod_dep = i_phase *
NUM_PROD_;
169 i_prod_dep < (i_phase + 1) *
NUM_PROD_; i_prod_dep++)
176 i_react_dep < (i_phase + 1) *
NUM_REACT_; i_react_dep++)
179 for (
int i_prod_dep = i_phase *
NUM_PROD_;
180 i_prod_dep < (i_phase + 1) *
NUM_PROD_; i_prod_dep++)
187 i_react_dep < (i_phase + 1) *
NUM_REACT_; ++i_react_dep)
189 for (
int i_prod_dep = i_phase *
NUM_PROD_;
190 i_prod_dep < (i_phase + 1) *
NUM_PROD_; ++i_prod_dep)
194 i_react_dep < (i_phase + 1) *
NUM_REACT_; ++i_react_dep)
197 for (
int i_prod_dep = i_phase *
NUM_PROD_;
198 i_prod_dep < (i_phase + 1) *
NUM_PROD_; ++i_prod_dep)
207 double *abs_tol = (
double *)model_data->
abs_tol;
210 for (
int i_react = 0; i_react <
NUM_REACT_; i_react++) {
216 for (
int i_prod = 0; i_prod <
NUM_PROD_; i_prod++) {
246 double *rxn_float_data,
247 double *rxn_env_data) {
248 int *int_data = rxn_int_data;
249 double *float_data = rxn_float_data;
279 double *rxn_env_data,
bool is_water_partial,
280 long double *rate_forward,
281 long double *rate_reverse) {
282 int *int_data = rxn_int_data;
283 double *float_data = rxn_float_data;
285 long double react_fact, prod_fact;
290 for (
int i_react = 1; i_react <
NUM_REACT_; i_react++) {
297 for (
int i_prod = 1; i_prod <
NUM_PROD_; i_prod++) {
305 if (is_water_partial) {
308 return *rate_forward - *rate_reverse;
322#ifdef CAMP_USE_SUNDIALS
325 double *rxn_float_data,
double *rxn_env_data,
double time_step) {
326 int *int_data = rxn_int_data;
327 double *float_data = rxn_float_data;
332 for (
int i_phase = 0, i_deriv = 0; i_phase <
NUM_AERO_PHASE_; i_phase++) {
334 long double water = state[
WATER_(i_phase)];
341 for (
int i_react = 0; i_react <
NUM_REACT_; ++i_react)
343 for (
int i_prod = 0; i_prod <
NUM_PROD_; ++i_prod)
353 long double rate_forward, rate_reverse;
356 &rate_forward, &rate_reverse);
363 for (
int i_react = 0; i_react <
NUM_REACT_; i_react++) {
375 for (
int i_prod = 0; i_prod <
NUM_PROD_; i_prod++) {
402#ifdef CAMP_USE_SUNDIALS
405 double *rxn_float_data,
406 double *rxn_env_data,
408 int *int_data = rxn_int_data;
409 double *float_data = rxn_float_data;
414 for (
int i_phase = 0, i_jac = 0; i_phase <
NUM_AERO_PHASE_; i_phase++) {
416 long double water = state[
WATER_(i_phase)];
424 for (
int i_react = 0; i_react <
NUM_REACT_; i_react++) {
431 for (
int i_prod = 0; i_prod <
NUM_PROD_; i_prod++) {
439 for (
int i_react_ind = 0; i_react_ind <
NUM_REACT_; i_react_ind++) {
440 for (
int i_react_dep = 0; i_react_dep <
NUM_REACT_; i_react_dep++) {
441 if (
JAC_ID_(i_jac) < 0 || forward_rate == 0.0) {
450 for (
int i_prod_dep = 0; i_prod_dep <
NUM_PROD_; i_prod_dep++) {
451 if (
JAC_ID_(i_jac) < 0 || forward_rate == 0.0) {
463 for (
int i_prod_ind = 0; i_prod_ind <
NUM_PROD_; i_prod_ind++) {
464 for (
int i_react_dep = 0; i_react_dep <
NUM_REACT_; i_react_dep++) {
465 if (
JAC_ID_(i_jac) < 0 || reverse_rate == 0.0) {
474 for (
int i_prod_dep = 0; i_prod_dep <
NUM_PROD_; i_prod_dep++) {
475 if (
JAC_ID_(i_jac) < 0 || reverse_rate == 0.0) {
487 for (
int i_react_dep = 0; i_react_dep <
NUM_REACT_; i_react_dep++) {
499 for (
int i_prod_dep = 0; i_prod_dep <
NUM_PROD_; i_prod_dep++) {
519 for (
int i_react_dep = 0; i_react_dep <
NUM_REACT_; i_react_dep++) {
529 for (
int i_prod_dep = 0; i_prod_dep <
NUM_PROD_; i_prod_dep++) {
550 int *int_data = rxn_int_data;
551 double *float_data = rxn_float_data;
553 printf(
"\n\nAqueous Equilibrium reaction\n");
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_aqueous_equilibrium_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.
#define SMALL_WATER_CONC_(x)
void rxn_aqueous_equilibrium_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.
#define RATE_CONST_REVERSE_
#define RATE_CONST_FORWARD_
void rxn_aqueous_equilibrium_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 from this reaction.
#define MASS_FRAC_TO_M_(x)
void rxn_aqueous_equilibrium_print(int *rxn_int_data, double *rxn_float_data)
Print the Aqueous Equilibrium reaction parameters.
#define ACTIVITY_COEFF_(x)
void rxn_aqueous_equilibrium_get_used_jac_elem(int *rxn_int_data, double *rxn_float_data, Jacobian *jac)
Flag Jacobian elements used by this reaction.
#define ACTIVITY_COEFF_VALUE_
void rxn_aqueous_equilibrium_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.
long double calc_standard_rate(int *rxn_int_data, double *rxn_float_data, double *rxn_env_data, bool is_water_partial, long double *rate_forward, long double *rate_reverse)
Calculate the reaction rate for a set of conditions using the standard equation per mixing ratio of w...
void time_derivative_add_value(TimeDerivative time_deriv, unsigned int spec_id, long double rate_contribution)
Add a contribution to the time derivative.