vector kinetics arrays

This commit is contained in:
David Parkhurst 2021-03-23 22:04:45 -06:00
parent 1850c32c93
commit bd0cad9434
5 changed files with 22 additions and 53 deletions

View File

@ -1061,11 +1061,7 @@ void Phreeqc::init(void)
kinetics_cvode_mem = NULL;
cvode_pp_assemblage_save= NULL;
cvode_ss_assemblage_save= NULL;
m_original = NULL;
m_temp = NULL;
rk_moles = NULL;
set_and_run_attempt = 0;
x0_moles = NULL;
/* model.cpp ------------------------------- */
gas_in = FALSE;
min_value = 1e-10;

View File

@ -1775,11 +1775,8 @@ public:
cxxSSassemblage *cvode_ss_assemblage_save;
cxxPPassemblage *cvode_pp_assemblage_save;
protected:
LDBLE *m_original;
LDBLE *m_temp;
LDBLE *rk_moles;
std::vector<double> m_temp, m_original, rk_moles, x0_moles;
int set_and_run_attempt;
LDBLE *x0_moles;
/* model.cpp ------------------------------- */
int gas_in;

View File

@ -236,17 +236,8 @@ read_calculate_values(void)
case OPT_1: /* read command */
if (calculate_value_ptr)
{
//length = (int) strlen(calculate_value_ptr->commands);
//line_length = (int) strlen(line);
//calculate_value_ptr->commands = (char *)PHRQ_realloc(calculate_value_ptr->commands,
// ((size_t)length + (size_t)line_length + 2) * sizeof(char));
//if (calculate_value_ptr->commands == NULL)
// malloc_error();
calculate_value_ptr->commands.append(";\0");
calculate_value_ptr->commands.append(line);
//calculate_value_ptr->commands[length] = ';';
//calculate_value_ptr->commands[length + 1] = '\0';
//strcat((calculate_value_ptr->commands), line);
opt_save = OPT_1;
}
else

View File

@ -338,9 +338,7 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver,
if (kinetics_ptr == NULL)
return (OK);
n_reactions = (int) kinetics_ptr->Get_kinetics_comps().size();
rk_moles = (LDBLE *) free_check_null(rk_moles);
rk_moles = (LDBLE *) PHRQ_malloc((size_t) 6 * n_reactions * sizeof(LDBLE));
if (rk_moles == NULL) malloc_error();
rk_moles.resize(6 * (size_t)n_reactions);
/*if (use_mix != NOMIX) last_model.force_prep = TRUE; */
set_and_run_wrapper(i, use_mix, FALSE, i, step_fraction);
@ -1112,7 +1110,7 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver,
{
Utilities::Rxn_copy(Rxn_solution_map, save_old, i);
}
rk_moles = (LDBLE *) free_check_null(rk_moles);
rk_moles.clear();
rate_sim_time = rate_sim_time_start + kin_time;
use.Set_kinetics_in(true);
@ -2040,14 +2038,8 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction)
* Save moles of kinetic reactants for printout...
*/
size_t count_comps = kinetics_ptr->Get_kinetics_comps().size();
m_temp = (LDBLE *) PHRQ_malloc(count_comps * sizeof(LDBLE));
if (m_temp == NULL)
malloc_error();
m_original =
(LDBLE *) PHRQ_malloc(count_comps * sizeof(LDBLE));
if (m_original == NULL)
malloc_error();
m_temp.resize(count_comps);
m_original.resize(count_comps);
for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++)
{
@ -2244,8 +2236,8 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction)
cvode_last_good_time = 0;
if (++m_iter >= kinetics_ptr->Get_bad_step_max())
{
m_temp = (LDBLE *) free_check_null(m_temp);
m_original = (LDBLE *) free_check_null(m_original);
m_temp.clear();
m_original.clear();
error_string = sformatf(
"CVode is at maximum calls: %d. Cell: %d. Time: %8.2e s\nERROR: Please increase the maximum calls with -bad_step_max.",
m_iter, cell_no, (double)sum_t);
@ -2349,8 +2341,8 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction)
kinetics_comp_ptr->Set_moles(m_original[j] - kinetics_comp_ptr->Get_m());
/* if (kinetics_ptr->comps[j].moles < 1.e-15) kinetics_ptr->comps[j].moles = 0.0;
*/ }
m_temp = (LDBLE *) free_check_null(m_temp);
m_original = (LDBLE *) free_check_null(m_original);
m_temp.clear();
m_original.clear();
}
iterations = run_reactions_iterations;
if (cvode_pp_assemblage_save != NULL)
@ -2651,13 +2643,8 @@ store_get_equi_reactants(int l, int kin_end)
if (k == 0)
return (OK);
x0_moles = (LDBLE *) free_check_null(x0_moles);
x0_moles = (LDBLE *) PHRQ_malloc((size_t) k * sizeof(LDBLE));
if (x0_moles == NULL) malloc_error();
for (i = 0; i < k; i++)
{
x0_moles[i] = 0.0;
}
x0_moles.resize(k);
for (i = 0; i < k; i++) x0_moles[i] = 0.0;
k = -1;
if (pp_assemblage_ptr)
{
@ -2740,7 +2727,7 @@ store_get_equi_reactants(int l, int kin_end)
* This condition makes output equal for incremental_reactions TRUE/FALSE...
* if (incremental_reactions == FALSE || reaction_step == count_total_steps)
*/
x0_moles = (LDBLE *) free_check_null(x0_moles);
x0_moles.clear();
}
return (OK);
}
@ -2849,7 +2836,8 @@ Jac(integertype N, DenseMat J, RhsFn f, void *f_data,
{
int count_cvode_errors;
int n_reactions, n_user;
LDBLE *initial_rates, del;
LDBLE del;
std::vector<double> initial_rates;
cxxKinetics *kinetics_ptr;
LDBLE step_fraction;
@ -2862,10 +2850,7 @@ Jac(integertype N, DenseMat J, RhsFn f, void *f_data,
step_fraction = pThis->cvode_step_fraction;
pThis->rate_sim_time = pThis->cvode_rate_sim_time;
initial_rates =
(LDBLE *) pThis->PHRQ_malloc ((size_t) n_reactions * sizeof(LDBLE));
if (initial_rates == NULL)
pThis->malloc_error();
initial_rates.resize(n_reactions);
for (size_t i = 0; i < kinetics_ptr->Get_kinetics_comps().size(); i++)
{
@ -2907,7 +2892,7 @@ Jac(integertype N, DenseMat J, RhsFn f, void *f_data,
/*
error_msg("Mass balance error in jacobian", CONTINUE);
*/
initial_rates = (LDBLE *) pThis->free_check_null(initial_rates);
initial_rates.clear();
return;
}
pThis->run_reactions_iterations += pThis->iterations;
@ -2979,7 +2964,7 @@ Jac(integertype N, DenseMat J, RhsFn f, void *f_data,
pThis->cvode_error = TRUE;
if (count_cvode_errors > 30)
{
initial_rates = (LDBLE *) pThis->free_check_null(initial_rates);
initial_rates.clear();
return;
}
pThis->run_reactions_iterations += pThis->iterations;
@ -3010,7 +2995,7 @@ Jac(integertype N, DenseMat J, RhsFn f, void *f_data,
cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[i]);
kinetics_comp_ptr->Set_moles(0);
}
initial_rates = (LDBLE *) pThis->free_check_null(initial_rates);
initial_rates.clear();
return;
}

View File

@ -127,10 +127,10 @@ clean_up(void)
Rxn_gas_phase_map.clear();
/* kinetics */
Rxn_kinetics_map.clear();
x0_moles = (LDBLE*)free_check_null(x0_moles);
m_temp = (LDBLE*)free_check_null(m_temp);
m_original = (LDBLE*)free_check_null(m_original);
rk_moles = (LDBLE*)free_check_null(rk_moles);
x0_moles.clear();
m_temp.clear();
m_original.clear();
rk_moles.clear();
/* rates */
for (j = 0; j < (int)rates.size(); j++)
{