base, sit arrays

This commit is contained in:
David Parkhurst 2021-03-24 08:31:54 -06:00
parent 90e8412074
commit 6907bb06c4
5 changed files with 22 additions and 52 deletions

View File

@ -1092,7 +1092,6 @@ void Phreeqc::init(void)
OPRESS = -100.;
A0 = 0;
aphi = NULL;
spec = NULL;
cations = NULL;
anions = NULL;
neutrals = NULL;
@ -1137,9 +1136,6 @@ void Phreeqc::init(void)
sit_MAXCATIONS = 0;
sit_FIRSTANION = 0;
sit_MAXNEUTRAL = 0;
sit_IPRSNT = NULL;
sit_M = NULL;
sit_LGAMMA = NULL;
/* tidy.cpp ------------------------------- */
a0 = 0;
a1 = 0;

View File

@ -1802,7 +1802,8 @@ protected:
LDBLE OTEMP, OPRESS;
LDBLE A0;
struct pitz_param* aphi;
struct species **spec, **cations, **anions, **neutrals;
std::vector<struct species*> spec;
struct species ** cations, ** anions, ** neutrals; // pointers to spec
int count_cations, count_anions, count_neutrals;
int MAXCATIONS, FIRSTANION, MAXNEUTRAL;
struct pitz_param *mcb0, *mcb1, *mcc0;
@ -1836,8 +1837,8 @@ protected:
LDBLE sit_A0;
int sit_count_cations, sit_count_anions, sit_count_neutrals;
int sit_MAXCATIONS, sit_FIRSTANION, sit_MAXNEUTRAL;
int *sit_IPRSNT;
LDBLE *sit_M, *sit_LGAMMA;
std::vector<int> sit_IPRSNT;
std::vector<double> sit_M, sit_LGAMMA;
std::vector<int> s_list, cation_list, neutral_list, anion_list, ion_list, param_list;
/* tidy.cpp ------------------------------- */

View File

@ -56,15 +56,9 @@ pitzer_tidy(void)
/*
* allocate pointers to species structures
*/
if (spec != NULL)
spec = (struct species **) free_check_null(spec);
spec = (struct species **)
PHRQ_malloc((size_t) (3 * s.size() * sizeof(struct species *)));
if (spec == NULL)
malloc_error();
for (i = 0; i < 3 * (int)s.size(); i++)
spec[i] = NULL;
cations = spec;
spec.clear();
spec.resize(3 * s.size(), NULL);
cations = &spec[0];
neutrals = &(spec[s.size()]);
anions = &(spec[2 * s.size()]);
MAXCATIONS = (int)s.size();
@ -1649,7 +1643,7 @@ pitzer_clean_up(void)
theta_params.clear();
LGAMMA.clear();
IPRSNT.clear();
spec = (struct species **) free_check_null(spec);
spec.clear();
aphi = (struct pitz_param *) free_check_null(aphi);
M.clear();

View File

@ -5814,9 +5814,8 @@ save_model(void)
}
/* charge */
last_model.count_surface_charge = (int) use.Get_surface_ptr()->Get_surface_charges().size();
last_model.surface_charge =
(const char **) PHRQ_malloc( use.Get_surface_ptr()->Get_surface_charges().size() *
sizeof(char *));
last_model.surface_charge =(const char **) PHRQ_malloc( use.Get_surface_ptr()->Get_surface_charges().size() *
sizeof(char *));
if (last_model.surface_charge == NULL)
malloc_error();
for (i = 0; i < (int) use.Get_surface_ptr()->Get_surface_charges().size(); i++)

44
sit.cpp
View File

@ -35,12 +35,10 @@ sit_tidy(void)
/*
* allocate pointers to species structures
*/
if (spec != NULL) spec = (struct species **) free_check_null(spec);
spec = (struct species **) PHRQ_malloc((size_t) (3 * s.size() * sizeof(struct species *)));
if (spec == NULL) malloc_error();
for (i = 0; i < 3 * (int)s.size(); i++) spec[i] = NULL;
spec.clear();
spec.resize(3 * s.size(), NULL);
cations = spec;
cations = &spec[0];
neutrals = &(spec[s.size()]);
anions = &(spec[2 * s.size()]);
sit_MAXCATIONS = (int)s.size();
@ -53,16 +51,9 @@ sit_tidy(void)
/*
* allocate other arrays for SIT
*/
if (sit_IPRSNT != NULL) sit_IPRSNT = (int *) free_check_null(sit_IPRSNT);
sit_IPRSNT = (int *) PHRQ_malloc((size_t) (3 * s.size() * sizeof(int)));
if (sit_IPRSNT == NULL) malloc_error();
if (sit_M != NULL) sit_M = (LDBLE *) free_check_null(sit_M);
sit_M = (LDBLE *) PHRQ_malloc((size_t) (3 * s.size() * sizeof(LDBLE)));
if (sit_M == NULL) malloc_error();
if (sit_LGAMMA != NULL) sit_LGAMMA = (LDBLE *) free_check_null(sit_LGAMMA);
sit_LGAMMA = (LDBLE *) PHRQ_malloc((size_t) (3 * s.size() * sizeof(LDBLE)));
if (sit_LGAMMA == NULL) malloc_error();
sit_IPRSNT.resize(3 * s.size());
sit_M.resize(3 * s.size());
sit_LGAMMA.resize(3 * s.size());
for (i = 0; i < (int)s.size(); i++)
{
@ -509,11 +500,11 @@ sit_clean_up(void)
}
sit_params.clear();
sit_param_map.clear();
sit_LGAMMA = (LDBLE *) free_check_null(sit_LGAMMA);
sit_IPRSNT = (int *) free_check_null(sit_IPRSNT);
spec = (struct species **) free_check_null(spec);
sit_LGAMMA.clear();
sit_IPRSNT.clear();
spec.clear();
aphi = (struct pitz_param *) free_check_null(aphi);
sit_M = (LDBLE *) free_check_null(sit_M);
sit_M.clear();
return OK;
}
@ -805,7 +796,7 @@ int Phreeqc::
jacobian_sit(void)
/* ---------------------------------------------------------------------- */
{
LDBLE *base;
std::vector<double> base;
LDBLE d, d1, d2;
int i, j;
Restart:
@ -817,16 +808,7 @@ Restart:
sit();
residuals();
}
base = (LDBLE *) PHRQ_malloc((size_t) count_unknowns * sizeof(LDBLE));
if (base == NULL)
{
malloc_error();
return OK;
}
for (i = 0; i < count_unknowns; i++)
{
base[i] = residual[i];
}
base = residual; // std::vectors
d = 0.0001;
d1 = d * LOG_10;
d2 = 0;
@ -900,7 +882,6 @@ Restart:
molalities(TRUE);
if (max_unknowns > pz_max_unknowns)
{
base = (LDBLE *) free_check_null(base);
gammas_sit();
jacobian_sums();
goto Restart;
@ -960,7 +941,6 @@ Restart:
sit();
mb_sums();
residuals();
free_check_null(base);
return OK;
}