13#include "../aero_phase_solver.h"
14#include "../aero_reps.h"
15#include "../camp_solver.h"
18#define TEMPERATURE_K_ env_data[0]
19#define PRESSURE_PA_ env_data[1]
21#define UPDATE_NUMBER 0
23#define NUM_LAYERS_ int_data[0]
24#define AERO_REP_ID_ int_data[1]
25#define MAX_PARTICLES_ int_data[2]
26#define PARTICLE_STATE_SIZE_ int_data[3]
27#define NUMBER_CONC_(x) aero_rep_env_data[x]
28#define NUM_INT_PROP_ 4
29#define NUM_FLOAT_PROP_ 0
30#define NUM_ENV_PARAM_ MAX_PARTICLES_
31#define LAYER_PHASE_START_(l) (int_data[NUM_INT_PROP_+l]-1)
32#define LAYER_PHASE_END_(l) (int_data[NUM_INT_PROP_+NUM_LAYERS_+l]-1)
33#define TOTAL_NUM_PHASES_ (LAYER_PHASE_END_(NUM_LAYERS_-1)-LAYER_PHASE_START_(0)+1)
34#define NUM_PHASES_(l) (LAYER_PHASE_END_(l)-LAYER_PHASE_START_(l)+1)
35#define PHASE_STATE_ID_(l,p) (int_data[NUM_INT_PROP_+2*NUM_LAYERS_+LAYER_PHASE_START_(l)+p]-1)
36#define PHASE_MODEL_DATA_ID_(l,p) (int_data[NUM_INT_PROP_+2*NUM_LAYERS_+TOTAL_NUM_PHASES_+LAYER_PHASE_START_(l)+p]-1)
37#define PHASE_NUM_JAC_ELEM_(l,p) int_data[NUM_INT_PROP_+2*NUM_LAYERS_+2*TOTAL_NUM_PHASES_+LAYER_PHASE_START_(l)+p]
54 int *aero_rep_int_data,
55 double *aero_rep_float_data,
57 int *int_data = aero_rep_int_data;
58 double *float_data = aero_rep_float_data;
64 for (
int i_layer = 0; i_layer <
NUM_LAYERS_; ++i_layer) {
65 for (
int i_phase = 0; i_phase <
NUM_PHASES_(i_layer); ++i_phase) {
87 double *aero_rep_float_data,
89 int *int_data = aero_rep_int_data;
90 double *float_data = aero_rep_float_data;
109 int *aero_rep_int_data,
110 double *aero_rep_float_data,
111 double *aero_rep_env_data) {
112 int *int_data = aero_rep_int_data;
113 double *float_data = aero_rep_float_data;
130 int *aero_rep_int_data,
131 double *aero_rep_float_data,
132 double *aero_rep_env_data) {
133 int *int_data = aero_rep_int_data;
134 double *float_data = aero_rep_float_data;
154 ModelData *model_data,
int aero_phase_idx,
double *radius,
155 double *partial_deriv,
int *aero_rep_int_data,
double *aero_rep_float_data,
156 double *aero_rep_env_data) {
158 int *int_data = aero_rep_int_data;
159 double *float_data = aero_rep_float_data;
161 double *curr_partial = NULL;
164 if (partial_deriv) curr_partial = partial_deriv;
165 for (
int i_layer = 0; i_layer <
NUM_LAYERS_; ++i_layer) {
166 for (
int i_phase = 0; i_phase <
NUM_PHASES_(i_layer); ++i_phase) {
171 state, &(volume), curr_partial);
176 *radius = pow(((*radius) * 3.0 / 4.0 / 3.14159265359), 1.0 / 3.0);
177 if (!partial_deriv)
return;
178 for (
int i_layer = 0; i_layer <
NUM_LAYERS_; ++i_layer) {
179 for (
int i_phase = 0; i_phase <
NUM_PHASES_(i_layer); ++i_phase) {
182 1.0 / 4.0 / 3.14159265359 * pow(*radius, -2.0) * (*partial_deriv);
213 ModelData *model_data,
int aero_phase_idx,
double *number_conc,
214 double *partial_deriv,
int *aero_rep_int_data,
double *aero_rep_float_data,
215 double *aero_rep_env_data) {
218 int *int_data = aero_rep_int_data;
219 double *float_data = aero_rep_float_data;
225 for (
int i_layer = 0; i_layer <
NUM_LAYERS_; ++i_layer) {
226 for (
int i_phase = 0; i_phase <
NUM_PHASES_(i_layer); ++i_phase) {
228 *(partial_deriv++) =
ZERO;
252 int *aero_rep_int_data,
253 double *aero_rep_float_data,
254 double *aero_rep_env_data) {
255 int *int_data = aero_rep_int_data;
256 double *float_data = aero_rep_float_data;
283 ModelData *model_data,
int aero_phase_idx,
double *aero_phase_mass,
284 double *partial_deriv,
int *aero_rep_int_data,
double *aero_rep_float_data,
285 double *aero_rep_env_data) {
287 int *int_data = aero_rep_int_data;
288 double *float_data = aero_rep_float_data;
292 int i_total_phase = 0;
293 for (
int i_layer = 0; i_layer <
NUM_LAYERS_; ++i_layer) {
294 for (
int i_phase = 0; i_phase <
NUM_PHASES_(i_layer); ++i_phase) {
295 if ( i_total_phase == aero_phase_idx ) {
300 aero_phase_mass, &mw, partial_deriv, NULL);
302 }
else if (partial_deriv) {
304 *(partial_deriv++) =
ZERO;
332 ModelData *model_data,
int aero_phase_idx,
double *aero_phase_avg_MW,
333 double *partial_deriv,
int *aero_rep_int_data,
double *aero_rep_float_data,
334 double *aero_rep_env_data) {
336 int *int_data = aero_rep_int_data;
337 double *float_data = aero_rep_float_data;
341 int i_total_phase = 0;
342 for (
int i_layer = 0; i_layer <
NUM_LAYERS_; ++i_layer) {
343 for (
int i_phase = 0; i_phase <
NUM_PHASES_(i_layer); ++i_phase) {
344 if ( i_total_phase == aero_phase_idx ) {
349 aero_phase_avg_MW, NULL, partial_deriv);
351 }
else if (partial_deriv) {
353 *(partial_deriv++) =
ZERO;
384 int *aero_rep_int_data,
385 double *aero_rep_float_data,
386 double *aero_rep_env_data) {
387 int *int_data = aero_rep_int_data;
388 double *float_data = aero_rep_float_data;
390 int *aero_rep_id = (
int *)update_data;
391 int *update_type = (
int *)&(aero_rep_id[1]);
392 int *particle_id = (
int *)&(update_type[1]);
393 double *new_value = (
double *)&(update_type[2]);
415 double *aero_rep_float_data) {
416 int *int_data = aero_rep_int_data;
417 double *float_data = aero_rep_float_data;
419 printf(
"\n\nSingle particle aerosol representation\n");
421 printf(
"\nAerosol representation id: %d",
AERO_REP_ID_);
424 for(
int i_layer = 0; i_layer <
NUM_LAYERS_; ++i_layer){
425 printf(
"\nLayer: %d", i_layer);
426 printf(
"\n\n - Phases -");
427 for (
int i_phase = 0; i_phase <
NUM_PHASES_(i_layer); ++i_phase) {
428 printf(
"\n state id: %d model data id: %d num Jac elements: %d",
433 printf(
"\n\nEnd single particle aerosol representation\n");
443 int *update_data = (
int *)malloc(3 *
sizeof(
int) +
sizeof(double));
444 if (update_data == NULL) {
445 printf(
"\n\nERROR allocating space for number update data\n\n");
448 return (
void *)update_data;
461 double number_conc) {
462 int *new_aero_rep_id = (
int *)update_data;
463 int *update_type = (
int *)&(new_aero_rep_id[1]);
464 int *new_particle_id = (
int *)&(update_type[1]);
465 double *new_number_conc = (
double *)&(update_type[2]);
466 *new_aero_rep_id = aero_rep_id;
468 *new_particle_id = particle_id;
469 *new_number_conc = number_conc;
void aero_phase_get_volume__m3_m3(ModelData *model_data, int aero_phase_idx, double *state_var, double *volume, double *jac_elem)
Get the volume of an aerosol phase.
int aero_phase_get_used_jac_elem(ModelData *model_data, int aero_phase_idx, int state_var_id, bool *jac_struct)
Flag Jacobian elements used in calculations of mass and volume.
void aero_phase_get_mass__kg_m3(ModelData *model_data, int aero_phase_idx, double *state_var, double *mass, double *MW, double *jac_elem_mass, double *jac_elem_MW)
Get the mass and average MW in an aerosol phase.
int aero_rep_single_particle_get_used_jac_elem(ModelData *model_data, int aero_phase_idx, int *aero_rep_int_data, double *aero_rep_float_data, bool *jac_struct)
Flag Jacobian elements used in calcualtions of mass and volume.
void aero_rep_single_particle_get_aero_phase_avg_MW__kg_mol(ModelData *model_data, int aero_phase_idx, double *aero_phase_avg_MW, double *partial_deriv, int *aero_rep_int_data, double *aero_rep_float_data, double *aero_rep_env_data)
Get the average molecular weight in an aerosol phase ( )
void aero_rep_single_particle_get_effective_radius__m(ModelData *model_data, int aero_phase_idx, double *radius, double *partial_deriv, int *aero_rep_int_data, double *aero_rep_float_data, double *aero_rep_env_data)
Get the effective particle radius (m)
#define PARTICLE_STATE_SIZE_
void aero_rep_single_particle_get_aero_conc_type(int aero_phase_idx, int *aero_conc_type, int *aero_rep_int_data, double *aero_rep_float_data, double *aero_rep_env_data)
Get the type of aerosol concentration used.
void * aero_rep_single_particle_create_number_update_data()
Create update data for new particle number.
#define PHASE_NUM_JAC_ELEM_(l, p)
void aero_rep_single_particle_print(int *aero_rep_int_data, double *aero_rep_float_data)
Print the Single Particle reaction parameters.
#define PHASE_MODEL_DATA_ID_(l, p)
#define TOTAL_NUM_PHASES_
#define PHASE_STATE_ID_(l, p)
void aero_rep_single_particle_update_env_state(ModelData *model_data, int *aero_rep_int_data, double *aero_rep_float_data, double *aero_rep_env_data)
Update aerosol representation data for new environmental conditions.
bool aero_rep_single_particle_update_data(void *update_data, int *aero_rep_int_data, double *aero_rep_float_data, double *aero_rep_env_data)
Update aerosol representation data.
void aero_rep_single_particle_get_dependencies(int *aero_rep_int_data, double *aero_rep_float_data, bool *state_flags)
Flag elements on the state array used by this aerosol representation.
void aero_rep_single_particle_get_aero_phase_mass__kg_m3(ModelData *model_data, int aero_phase_idx, double *aero_phase_mass, double *partial_deriv, int *aero_rep_int_data, double *aero_rep_float_data, double *aero_rep_env_data)
Get the total mass in an aerosol phase ( )
void aero_rep_single_particle_get_number_conc__n_m3(ModelData *model_data, int aero_phase_idx, double *number_conc, double *partial_deriv, int *aero_rep_int_data, double *aero_rep_float_data, double *aero_rep_env_data)
Get the particle number concentration ( )
void aero_rep_single_particle_set_number_update_data__n_m3(void *update_data, int aero_rep_id, int particle_id, double number_conc)
Set number update data (#/m3)
void aero_rep_single_particle_update_state(ModelData *model_data, int *aero_rep_int_data, double *aero_rep_float_data, double *aero_rep_env_data)
Update aerosol representation data for a new state.