14#include "../aero_rep_solver.h"
19#define TEMPERATURE_K_ env_data[0]
20#define PRESSURE_PA_ env_data[1]
24#define MIN_WATER_ 1.0e-4
30#define DELTA_H_ float_data[0]
31#define DELTA_S_ float_data[1]
32#define DIFF_COEFF_ float_data[2]
33#define PRE_C_AVG_ float_data[3]
34#define A_ float_data[4]
35#define C_ float_data[5]
36#define CONV_ float_data[6]
37#define MW_ float_data[7]
38#define NUM_AERO_PHASE_ int_data[0]
39#define GAS_SPEC_ (int_data[1] - 1)
40#define MFP_M_ rxn_env_data[0]
41#define ALPHA_ rxn_env_data[1]
42#define EQUIL_CONST_ rxn_env_data[2]
43#define KGM3_TO_PPM_ rxn_env_data[3]
44#define NUM_INT_PROP_ 2
45#define NUM_FLOAT_PROP_ 8
46#define NUM_ENV_PARAM_ 4
47#define DERIV_ID_(x) int_data[NUM_INT_PROP_ + x]
48#define JAC_ID_(x) int_data[NUM_INT_PROP_ + 1 + NUM_AERO_PHASE_ + x]
49#define PHASE_INT_LOC_(x) \
50 (int_data[NUM_INT_PROP_ + 2 + 6 * NUM_AERO_PHASE_ + x] - 1)
51#define PHASE_REAL_LOC_(x) \
52 (int_data[NUM_INT_PROP_ + 2 + 7 * NUM_AERO_PHASE_ + x] - 1)
53#define AERO_SPEC_(x) (int_data[PHASE_INT_LOC_(x)] - 1)
54#define AERO_WATER_(x) (int_data[PHASE_INT_LOC_(x) + 1] - 1)
55#define AERO_PHASE_ID_(x) (int_data[PHASE_INT_LOC_(x) + 2] - 1)
56#define AERO_REP_ID_(x) (int_data[PHASE_INT_LOC_(x) + 3] - 1)
57#define NUM_AERO_PHASE_JAC_ELEM_(x) (int_data[PHASE_INT_LOC_(x) + 4])
58#define PHASE_JAC_ID_(x, s, e) \
59 int_data[PHASE_INT_LOC_(x) + 5 + (s) * NUM_AERO_PHASE_JAC_ELEM_(x) + e]
60#define SMALL_WATER_CONC_(x) (float_data[PHASE_REAL_LOC_(x)])
61#define EFF_RAD_JAC_ELEM_(x, e) float_data[PHASE_REAL_LOC_(x) + 1 + e]
62#define NUM_CONC_JAC_ELEM_(x, e) \
63 float_data[PHASE_REAL_LOC_(x) + 1 + NUM_AERO_PHASE_JAC_ELEM_(x) + e]
74 double *rxn_float_data,
76 int *int_data = rxn_int_data;
77 double *float_data = rxn_float_data;
81 if (aero_jac_elem == NULL) {
83 "\n\nERROR allocating space for 1D jacobian structure array for HL "
84 "partitioning reaction\n\n");
89 for (
int i_aero_phase = 0; i_aero_phase <
NUM_AERO_PHASE_; i_aero_phase++) {
99 aero_jac_elem[i_elem] =
false;
106 "\n\nERROR Received more Jacobian elements than expected for HL "
107 "partitioning reaction. Got %d, expected <= %d",
113 if (aero_jac_elem[i_elem] ==
true) {
126 if (i_used_elem != n_jac_elem) {
128 "\n\nERROR Error setting used Jacobian elements in HL "
129 "partitioning reaction %d %d\n\n",
130 i_used_elem, n_jac_elem);
151 double *rxn_float_data) {
152 int *int_data = rxn_int_data;
153 double *float_data = rxn_float_data;
163 for (
int i_aero_phase = 0; i_aero_phase <
NUM_AERO_PHASE_; i_aero_phase++) {
191 double *abs_tol = (
double *)model_data->
abs_tol;
192 for (
int i_aero_phase = 0; i_aero_phase <
NUM_AERO_PHASE_; i_aero_phase++) {
211 double *rxn_float_data,
212 double *rxn_env_data) {
213 int *int_data = rxn_int_data;
214 double *float_data = rxn_float_data;
264#ifdef CAMP_USE_SUNDIALS
267 double *rxn_float_data,
double *rxn_env_data, realtype time_step) {
268 int *int_data = rxn_int_data;
269 double *float_data = rxn_float_data;
293 realtype number_conc =
ONE;
294 if (aero_conc_type == 0) {
306 long double cond_rate =
307 ((
long double)1.0) / (radius * radius / (3.0 *
DIFF_COEFF_) +
308 4.0 * radius / (3.0 *
MFP_M_));
313 long double cond_rate =
326 number_conc * evap_rate);
328 -number_conc * cond_rate);
353#ifdef CAMP_USE_SUNDIALS
356 double *rxn_float_data,
357 double *rxn_env_data,
358 realtype time_step) {
359 int *int_data = rxn_int_data;
360 double *float_data = rxn_float_data;
384 realtype number_conc =
ONE;
385 if (aero_conc_type == 0) {
400 long double cond_rate = 1.0 / (radius * radius / (3.0 *
DIFF_COEFF_) +
401 4.0 * radius / (3.0 *
MFP_M_));
406 long double cond_rate =
415 number_conc * cond_rate);
416 if (
JAC_ID_(1 + i_phase * 5 + 1) >= 0)
419 number_conc * evap_rate / state[
AERO_WATER_(i_phase)]);
420 if (
JAC_ID_(1 + i_phase * 5 + 3) >= 0)
423 -number_conc * evap_rate * state[
AERO_SPEC_(i_phase)] /
428 if (
JAC_ID_(1 + i_phase * 5) >= 0)
431 if (
JAC_ID_(1 + i_phase * 5 + 2) >= 0)
435 if (
JAC_ID_(1 + i_phase * 5 + 4) >= 0)
450 long double d_rate_d_radius =
454 long double d_cond_d_radius =
457 long double d_evap_d_radius = d_cond_d_radius / state[
GAS_SPEC_] /
511 int *int_data = rxn_int_data;
512 double *float_data = rxn_float_data;
514 printf(
"\n\nPhase Transfer 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
int aero_rep_get_aero_conc_type(ModelData *model_data, int aero_rep_idx, int aero_phase_idx)
Check whether aerosol concentrations are per-particle or total for each phase.
int aero_rep_get_used_jac_elem(ModelData *model_data, int aero_rep_idx, int aero_phase_idx, bool *jac_struct)
Flag Jacobian elements used to calculated mass, volume, etc.
void aero_rep_get_number_conc__n_m3(ModelData *model_data, int aero_rep_idx, int aero_phase_idx, double *number_conc, double *partial_deriv)
Get the particle number concentration ( )
void aero_rep_get_effective_radius__m(ModelData *model_data, int aero_rep_idx, int aero_phase_idx, double *radius, double *partial_deriv)
Get the effective particle radius, (m)
#define SMALL_WATER_CONC_(x)
void rxn_HL_phase_transfer_print(int *rxn_int_data, double *rxn_float_data)
Print the Phase Transfer reaction parameters.
#define AERO_PHASE_ID_(x)
void rxn_HL_phase_transfer_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.
void rxn_HL_phase_transfer_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_HL_phase_transfer_get_used_jac_elem(ModelData *model_data, int *rxn_int_data, double *rxn_float_data, Jacobian *jac)
Flag Jacobian elements used by this reaction.
void rxn_HL_phase_transfer_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_HL_phase_transfer_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.
#define PHASE_JAC_ID_(x, s, e)
#define NUM_AERO_PHASE_JAC_ELEM_(x)
#define EFF_RAD_JAC_ELEM_(x, e)
#define NUM_CONC_JAC_ELEM_(x, e)
void time_derivative_add_value(TimeDerivative time_deriv, unsigned int spec_id, long double rate_contribution)
Add a contribution to the time derivative.
static double d_gas_aerosol_transition_rxn_rate_constant_d_radius(double diffusion_coeff__m2_s, double mean_free_path__m, double radius__m, double alpha)
static double gas_aerosol_transition_rxn_rate_constant(double diffusion_coeff__m2_s, double mean_free_path__m, double radius__m, double alpha)
static double mean_free_path__m(double diffusion_coeff__m2_s, double temperature__K, double mw__kg_mol)