Skip to content

Commit

Permalink
update calls to aero phase functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mattldawson committed Feb 5, 2025
1 parent a57e21a commit 31ac320
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 37 deletions.
8 changes: 0 additions & 8 deletions src/aero_phase_solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ int aero_phase_get_used_jac_elem(ModelData *model_data, int aero_phase_idx,
[model_data->aero_phase_float_indices[aero_phase_idx]]);

int num_flagged_elem = 0;
printf("\n\n aero_phase_idx jac elem: %d", aero_phase_idx);
printf("\n int_data ptr: %d", *int_data);

for (int i_spec = 0; i_spec < NUM_STATE_VAR_; i_spec++) {
printf("\n NUM_STATE_VAR_: %d", NUM_STATE_VAR_);
printf("\n i_spec: %d", i_spec);
if (SPEC_TYPE_(i_spec) == CHEM_SPEC_VARIABLE ||
SPEC_TYPE_(i_spec) == CHEM_SPEC_CONSTANT ||
SPEC_TYPE_(i_spec) == CHEM_SPEC_PSSA) {
Expand Down Expand Up @@ -108,11 +104,7 @@ void aero_phase_get_mass__kg_m3(ModelData *model_data, int aero_phase_idx,
long double l_mass = MINIMUM_MASS_;
long double moles = MINIMUM_MASS_ / MINIMUM_MW_;
int i_jac = 0;
printf("\n\n aero_phase_idx mass MW: %d", aero_phase_idx);
printf("\n int_data ptr mass MW: %d", *int_data);
for (int i_spec = 0; i_spec < NUM_STATE_VAR_; i_spec++) {
printf("\n i_spec: %d", i_spec);
printf("\n NUM_STATE_VAR_ mass MW: %d", NUM_STATE_VAR_);
if (SPEC_TYPE_(i_spec) == CHEM_SPEC_VARIABLE ||
SPEC_TYPE_(i_spec) == CHEM_SPEC_CONSTANT ||
SPEC_TYPE_(i_spec) == CHEM_SPEC_PSSA) {
Expand Down
1 change: 1 addition & 0 deletions src/aero_reps/aero_rep_single_particle.F90
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ subroutine initialize(this, aero_phase_set, spec_state_id)
exit
end if
end do
call assert(373124707, found)

call phases(j_layer)%val_%iter_next()
end do
Expand Down
18 changes: 6 additions & 12 deletions src/aero_reps/aero_rep_single_particle.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,11 @@ void aero_rep_single_particle_get_effective_radius__m(
if (partial_deriv) curr_partial = partial_deriv;
for (int i_layer = 0; i_layer < NUM_LAYERS_; ++i_layer) {
for (int i_phase = 0; i_phase < NUM_PHASES_(i_layer); ++i_phase) {
//printf("\n i_layer: %d", i_layer);
//printf("\n i_phase: %d", i_phase);
double *state = (double *)(model_data->grid_cell_state);
state += i_part * PARTICLE_STATE_SIZE_ + PHASE_STATE_ID_(i_layer,i_phase);
//printf("\n particle state size : %d", PARTICLE_STATE_SIZE_);
//printf("\n phase state id : %d", PHASE_STATE_ID_(i_layer,i_phase));
double volume;
aero_phase_get_volume__m3_m3(model_data, PHASE_MODEL_DATA_ID_(i_layer,i_phase),
state, &(volume), curr_partial);
//printf("\n phase_model_data_id : %d", PHASE_MODEL_DATA_ID_(i_layer,i_phase));
//printf("\n volume : %f", volume);
if (partial_deriv) curr_partial += PHASE_NUM_JAC_ELEM_(i_layer,i_phase);
*radius += volume;
}
Expand Down Expand Up @@ -294,7 +288,6 @@ void aero_rep_single_particle_get_aero_phase_mass__kg_m3(
double *float_data = aero_rep_float_data;
int i_part = aero_phase_idx / TOTAL_NUM_PHASES_;
aero_phase_idx -= i_part * TOTAL_NUM_PHASES_;
printf("\n aero_phase_idx %d", aero_phase_idx);

int i_total_phase = 0;
for (int i_layer = 0; i_layer < NUM_LAYERS_; ++i_layer) {
Expand All @@ -303,8 +296,8 @@ void aero_rep_single_particle_get_aero_phase_mass__kg_m3(
double *state = (double *)(model_data->grid_cell_state);
state += i_part * PARTICLE_STATE_SIZE_ + PHASE_STATE_ID_(i_layer,i_phase);
double mw;
aero_phase_get_mass__kg_m3(model_data, aero_phase_idx, state,
aero_phase_mass, &mw, partial_deriv, NULL);
aero_phase_get_mass__kg_m3(model_data, PHASE_MODEL_DATA_ID_(i_layer,i_phase),
state, aero_phase_mass, &mw, partial_deriv, NULL);
if (partial_deriv) partial_deriv += PHASE_NUM_JAC_ELEM_(i_layer,i_phase);
} else if (partial_deriv) {
for (int i_spec = 0; i_spec < PHASE_NUM_JAC_ELEM_(i_layer,i_phase); ++i_spec)
Expand Down Expand Up @@ -348,13 +341,12 @@ void aero_rep_single_particle_get_aero_phase_avg_MW__kg_mol(
int i_total_phase = 0;
for (int i_layer = 0; i_layer < NUM_LAYERS_; ++i_layer) {
for (int i_phase = 0; i_phase < NUM_PHASES_(i_layer); ++i_phase) {
printf("\n MW NUM_PHASES_ %d", NUM_PHASES_(i_layer));
if ( i_total_phase == aero_phase_idx ) {
double *state = (double *)(model_data->grid_cell_state);
state += i_part * PARTICLE_STATE_SIZE_ + PHASE_STATE_ID_(i_layer,i_phase);
double mass;
aero_phase_get_mass__kg_m3(model_data, aero_phase_idx, state, &mass,
aero_phase_avg_MW, NULL, partial_deriv);
aero_phase_get_mass__kg_m3(model_data, PHASE_MODEL_DATA_ID_(i_layer,i_phase),
state, &mass, aero_phase_avg_MW, NULL, partial_deriv);
if (partial_deriv) partial_deriv += PHASE_NUM_JAC_ELEM_(i_layer,i_phase);
} else if (partial_deriv) {
for (int i_spec = 0; i_spec < PHASE_NUM_JAC_ELEM_(i_layer,i_phase); ++i_spec)
Expand Down Expand Up @@ -431,6 +423,8 @@ void aero_rep_single_particle_print(int *aero_rep_int_data,
printf("\nParticle state size: %d", PARTICLE_STATE_SIZE_);
for(int i_layer = 0; i_layer < NUM_LAYERS_; ++i_layer){
printf("\nLayer: %d", i_layer);
printf("\n Start phase: %d End phase: %d", LAYER_PHASE_START_(i_layer), LAYER_PHASE_END_(i_layer));
printf("\n Number of phases: %d", NUM_PHASES_(i_layer));
printf("\n\n - Phases -");
for (int i_phase = 0; i_phase < NUM_PHASES_(i_layer); ++i_phase) {
printf("\n state id: %d model data id: %d num Jac elements: %d",
Expand Down
4 changes: 3 additions & 1 deletion test/unit_aero_rep_data/test_aero_rep_single_particle.F90
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ program camp_test_aero_rep_data
integer(kind=i_kind), parameter :: NUM_AERO_PHASE = 4

! Index for the test phase
! (test-particle 1 phase 2 : middle layer, jam)
integer(kind=i_kind), parameter :: AERO_PHASE_IDX_1 = ((TEST_PARTICLE_1-1)*NUM_AERO_PHASE+2)
integer(kind=i_kind), parameter :: AERO_PHASE_IDX_2 = ((TEST_PARTICLE_2)*NUM_AERO_PHASE)
! (test-particle 1 phase 4 : top layer, top bread)
integer(kind=i_kind), parameter :: AERO_PHASE_IDX_2 = ((TEST_PARTICLE_1-1)*NUM_AERO_PHASE+4)

! Number of expected Jacobian elements for the test phase
integer(kind=i_kind), parameter :: NUM_JAC_ELEM = 12
Expand Down
22 changes: 6 additions & 16 deletions test/unit_aero_rep_data/test_aero_rep_single_particle.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@

// test computational particle
#define TEST_PARTICLE_1 2
#define TEST_PARTICLE_2 1

// number of computational particles in the test
#define N_COMP_PARTICLES 3

// number of aerosol phases per particle
#define NUM_AERO_PHASE 4

// index for the test phase (test-particle phase 2)
// index for the test phase
// (test-particle phase 2 : middle layer, jam)
#define AERO_PHASE_IDX_1 ((TEST_PARTICLE_1-1)*NUM_AERO_PHASE+1)
#define AERO_PHASE_IDX_2 ((TEST_PARTICLE_2)*NUM_AERO_PHASE-1)
// (test-particle phase 4 : top layer, bread)
#define AERO_PHASE_IDX_2 ((TEST_PARTICLE_1-1)*NUM_AERO_PHASE+3)

// number of Jacobian elements used for the test phase
#define N_JAC_ELEM 12
Expand Down Expand Up @@ -381,26 +382,15 @@ int run_aero_rep_single_particle_c_tests(void *solver_data, double *state, doubl
NV_DATA_S(solver_state)[(TEST_PARTICLE_1-1)*12+10] = state[(TEST_PARTICLE_1-1)*12+10] = CONC_water; // layer three, phase one
NV_DATA_S(solver_state)[(TEST_PARTICLE_1-1)*12+11] = state[(TEST_PARTICLE_1-1)*12+11] = CONC_salt; // layer three, phase one

NV_DATA_S(solver_state)[(TEST_PARTICLE_2-1)*12+0] = state[(TEST_PARTICLE_2-1)*12+0] = CONC_wheat; // layer one, phase one
NV_DATA_S(solver_state)[(TEST_PARTICLE_2-1)*12+1] = state[(TEST_PARTICLE_2-1)*12+1] = CONC_water; // layer one, phase one
NV_DATA_S(solver_state)[(TEST_PARTICLE_2-1)*12+2] = state[(TEST_PARTICLE_2-1)*12+2] = CONC_salt; // layer one, phase one
NV_DATA_S(solver_state)[(TEST_PARTICLE_2-1)*12+3] = state[(TEST_PARTICLE_2-1)*12+3] = CONC_rasberry; // layer two, phase one
NV_DATA_S(solver_state)[(TEST_PARTICLE_2-1)*12+4] = state[(TEST_PARTICLE_2-1)*12+4] = CONC_honey; // layer two, phase one
NV_DATA_S(solver_state)[(TEST_PARTICLE_2-1)*12+5] = state[(TEST_PARTICLE_2-1)*12+5] = CONC_sugar; // layer two, phase one
NV_DATA_S(solver_state)[(TEST_PARTICLE_2-1)*12+6] = state[(TEST_PARTICLE_2-1)*12+6] = CONC_lemon; // layer two, phase one
NV_DATA_S(solver_state)[(TEST_PARTICLE_2-1)*12+7] = state[(TEST_PARTICLE_2-1)*12+7] = CONC_almonds; // layer two, phase two
NV_DATA_S(solver_state)[(TEST_PARTICLE_2-1)*12+8] = state[(TEST_PARTICLE_2-1)*12+8] = CONC_sugar; // layer two, phase two
NV_DATA_S(solver_state)[(TEST_PARTICLE_2-1)*12+9] = state[(TEST_PARTICLE_2-1)*12+9] = CONC_wheat; // layer three, phase one
NV_DATA_S(solver_state)[(TEST_PARTICLE_2-1)*12+10] = state[(TEST_PARTICLE_2-1)*12+10] = CONC_water; // layer three, phase one
NV_DATA_S(solver_state)[(TEST_PARTICLE_2-1)*12+11] = state[(TEST_PARTICLE_2-1)*12+11] = CONC_salt; // layer three, phase one

// Set the environment-dependent parameter pointer to the first grid cell
model_data->grid_cell_aero_rep_env_data = model_data->aero_rep_env_data;

// Update the environmental and concentration states
aero_rep_update_env_state(model_data);
aero_rep_update_state(model_data);

aero_rep_print_data(sd);

// Run the property tests
ret_val += test_effective_radius(model_data, solver_state);
ret_val += test_aero_phase_mass(model_data, solver_state);
Expand Down

0 comments on commit 31ac320

Please sign in to comment.