mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-15 16:18:22 +01:00
Merge commit 'b1efa4f251731679e57d36e20579687b2d1efce2'
This commit is contained in:
commit
eb19293d49
@ -87,7 +87,7 @@ cxxNumKeyword(io)
|
||||
point_added = false;
|
||||
|
||||
user_graph = new rate;
|
||||
user_graph->commands = NULL;
|
||||
user_graph->commands.clear();
|
||||
user_graph->name = NULL;
|
||||
user_graph->new_def = 0;
|
||||
user_graph->linebase = user_graph->loopbase = user_graph->varbase = NULL;
|
||||
@ -837,11 +837,7 @@ ChartObject::Set_rate_struct(void)
|
||||
oss << *it << "\n";
|
||||
}
|
||||
this->Rate_free();
|
||||
if (this->phreeqc_ptr)
|
||||
{
|
||||
this->user_graph->commands = (char *) phreeqc_ptr-> PHRQ_malloc((oss.str().size()) + 100 * sizeof(char));
|
||||
}
|
||||
::strcpy(this->user_graph->commands, oss.str().c_str());
|
||||
this->user_graph->commands = oss.str().c_str();
|
||||
this->user_graph->new_def = this->rate_new_def;
|
||||
this->user_graph->loopbase = NULL;
|
||||
this->user_graph->varbase = NULL;
|
||||
@ -1074,7 +1070,7 @@ ChartObject::Rate_free(void)
|
||||
|
||||
if (this->phreeqc_ptr)
|
||||
{
|
||||
user_graph->commands = (char *) phreeqc_ptr-> free_check_null(user_graph->commands);
|
||||
user_graph->commands.clear();
|
||||
}
|
||||
if (user_graph->linebase != NULL)
|
||||
{
|
||||
|
||||
@ -87,14 +87,6 @@ class cxxExchComp: public PHRQ_base
|
||||
{
|
||||
this->formula_z = d;
|
||||
}
|
||||
void Set_totals(struct elt_list *e_l, int count)
|
||||
{
|
||||
this->totals = cxxNameDouble(e_l, count);
|
||||
}
|
||||
void Set_totals(struct elt_list *e_l)
|
||||
{
|
||||
this->totals = cxxNameDouble(e_l);
|
||||
}
|
||||
void Set_totals(cxxNameDouble nd)
|
||||
{
|
||||
this->totals = nd;
|
||||
|
||||
@ -23,7 +23,7 @@ cxxISolution::cxxISolution(PHRQ_io *io)
|
||||
units("mMol/kgw")
|
||||
{
|
||||
default_pe = "pe";
|
||||
cxxChemRxn temp_pe_reactions;
|
||||
CReaction temp_pe_reactions;
|
||||
pe_reactions[default_pe] = temp_pe_reactions;
|
||||
this->calc_density = false;
|
||||
|
||||
|
||||
@ -38,17 +38,15 @@ class cxxISolution: public PHRQ_base
|
||||
std::map < std::string, cxxISolutionComp > &Get_comps(void) {return this->comps;}
|
||||
const std::map < std::string, cxxISolutionComp > &Get_comps(void)const {return this->comps;}
|
||||
void Set_comps(std::map < std::string, cxxISolutionComp > &c) {this->comps = c;}
|
||||
std::map < std::string, cxxChemRxn > &Get_pe_reactions(void) {return this->pe_reactions;}
|
||||
void Set_pe_reactions(std::map < std::string, cxxChemRxn > &pe) {this->pe_reactions = pe;}
|
||||
//void dump_xml(std::ostream& os, unsigned int indent = 0)const;
|
||||
//void ConvertUnits(Phreeqc * phreeqc_ptr);
|
||||
std::map<std::string, CReaction>& Get_pe_reactions(void) { return this->pe_reactions; }
|
||||
void Set_pe_reactions(std::map < std::string, CReaction >& pe) { this->pe_reactions = pe; }
|
||||
|
||||
protected:
|
||||
friend class cxxISolutionComp; // for this->pe access
|
||||
std::string units;
|
||||
bool calc_density;
|
||||
std::map < std::string, cxxISolutionComp > comps;
|
||||
std::map <std::string, cxxChemRxn > pe_reactions;
|
||||
std::map <std::string, CReaction> pe_reactions;
|
||||
const char * default_pe;
|
||||
};
|
||||
|
||||
|
||||
@ -29,39 +29,17 @@ cxxNameDouble::cxxNameDouble()
|
||||
{
|
||||
this->type = ND_ELT_MOLES;
|
||||
}
|
||||
|
||||
cxxNameDouble::cxxNameDouble(struct elt_list *elt_list_ptr)
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list
|
||||
//
|
||||
cxxNameDouble::cxxNameDouble(const std::vector<struct elt_list>& el)
|
||||
// constructor for cxxNameDouble from vector of elt_list
|
||||
{
|
||||
int i;
|
||||
if (elt_list_ptr != NULL)
|
||||
size_t i;
|
||||
const struct elt_list* elt_list_ptr = &el[0];
|
||||
for (i = 0; elt_list_ptr[i].elt != NULL; i++)
|
||||
{
|
||||
for (i = 0; elt_list_ptr[i].elt != NULL; i++)
|
||||
{
|
||||
(*this)[elt_list_ptr[i].elt->name] = elt_list_ptr[i].coef;
|
||||
}
|
||||
(*this)[elt_list_ptr[i].elt->name] = elt_list_ptr[i].coef;
|
||||
}
|
||||
this->type = ND_ELT_MOLES;
|
||||
}
|
||||
|
||||
cxxNameDouble::cxxNameDouble(struct elt_list *elt_list_ptr, int count)
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list with known count
|
||||
//
|
||||
{
|
||||
int i;
|
||||
if (elt_list_ptr != NULL)
|
||||
{
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
(*this)[elt_list_ptr[i].elt->name] = elt_list_ptr[i].coef;
|
||||
}
|
||||
}
|
||||
this->type = ND_ELT_MOLES;
|
||||
}
|
||||
|
||||
cxxNameDouble::cxxNameDouble(const cxxNameDouble & old, LDBLE factor)
|
||||
//
|
||||
// constructor for cxxNameDouble from list of elt_list
|
||||
|
||||
@ -28,8 +28,7 @@ class IPQ_DLL_EXPORT cxxNameDouble:public
|
||||
};
|
||||
|
||||
cxxNameDouble();
|
||||
cxxNameDouble(struct elt_list *);
|
||||
cxxNameDouble(struct elt_list *, int count);
|
||||
cxxNameDouble(const std::vector<struct elt_list>& el);
|
||||
cxxNameDouble(std::map < std::string, cxxISolutionComp > &comps);
|
||||
|
||||
cxxNameDouble(struct name_coef *nc, int count);
|
||||
|
||||
@ -135,6 +135,7 @@ cxxNumKeyword::read_number_description(const std::string & line_in)
|
||||
std::string line = line_in;
|
||||
std::string::iterator b = line.begin();
|
||||
std::string::iterator e = line.end();
|
||||
this->description.clear();
|
||||
// skip keyword
|
||||
CParser::copy_token(keyword, b, e);
|
||||
|
||||
@ -168,11 +169,11 @@ cxxNumKeyword::read_number_description(const std::string & line_in)
|
||||
else
|
||||
{
|
||||
this->n_user = this->n_user_end = 1;
|
||||
this->description = token;
|
||||
}
|
||||
|
||||
// skip whitespace
|
||||
std::string::iterator ic;
|
||||
this->description.clear();
|
||||
for (ic = b; ic != e; ic++)
|
||||
{
|
||||
this->description += *ic;
|
||||
|
||||
@ -70,14 +70,13 @@ PBasic::PBasic(Phreeqc * ptr, PHRQ_io *phrq_io)
|
||||
}
|
||||
PBasic::~PBasic(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int PBasic::
|
||||
basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase)
|
||||
basic_compile(const char *commands, void **lnbase, void **vbase, void **lpbase)
|
||||
{ /*main */
|
||||
int l;
|
||||
char *ptr;
|
||||
const char *ptr;
|
||||
|
||||
P_escapecode = 0;
|
||||
P_ioresult = 0;
|
||||
@ -164,7 +163,7 @@ int PBasic::
|
||||
basic_renumber(char *commands, void **lnbase, void **vbase, void **lpbase)
|
||||
{ /*main */
|
||||
int l, i;
|
||||
char *ptr;
|
||||
const char *ptr;
|
||||
|
||||
P_escapecode = 0;
|
||||
P_ioresult = 0;
|
||||
@ -245,7 +244,7 @@ int PBasic::
|
||||
basic_run(char *commands, void *lnbase, void *vbase, void *lpbase)
|
||||
{ /*main */
|
||||
int l;
|
||||
char *ptr;
|
||||
const char *ptr;
|
||||
P_escapecode = 0;
|
||||
P_ioresult = 0;
|
||||
inbuf = (char *) PhreeqcPtr->PHRQ_calloc(PhreeqcPtr->max_line, sizeof(char));
|
||||
@ -317,10 +316,10 @@ basic_run(char *commands, void *lnbase, void *vbase, void *lpbase)
|
||||
}
|
||||
|
||||
int PBasic::
|
||||
basic_main(char *commands)
|
||||
basic_main(const char *commands)
|
||||
{ /*main */
|
||||
int l;
|
||||
char *ptr;
|
||||
const char *ptr;
|
||||
|
||||
P_escapecode = 0;
|
||||
P_ioresult = 0;
|
||||
@ -379,7 +378,7 @@ basic_main(char *commands)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int PBasic::
|
||||
sget_logical_line(char **ptr, int *l, char *return_line)
|
||||
sget_logical_line(const char **ptr, int *l, char *return_line)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -723,7 +722,7 @@ parse(char * l_inbuf, tokenrec ** l_buf)
|
||||
* Note: Modification of string length may translate incorrectly [146] */
|
||||
|
||||
/*
|
||||
* Search hash list
|
||||
* Search list
|
||||
*/
|
||||
PhreeqcPtr->str_tolower(token);
|
||||
std::map<const std::string, BASIC_TOKEN>::const_iterator item;
|
||||
@ -2021,8 +2020,6 @@ factor(struct LOC_exec * LINK)
|
||||
long i;
|
||||
char *c;
|
||||
} trick;
|
||||
struct save_values s_v, *s_v_ptr;
|
||||
int k;
|
||||
LDBLE TEMP;
|
||||
std::string STR1, STR2;
|
||||
const char *elt_name, *surface_name, *mytemplate, *name;
|
||||
@ -2039,9 +2036,6 @@ factor(struct LOC_exec * LINK)
|
||||
facttok = LINK->t;
|
||||
LINK->t = LINK->t->next;
|
||||
n.stringval = false;
|
||||
s_v.count_subscripts = 0;
|
||||
/*s_v.subscripts = (int *) PhreeqcPtr->PHRQ_malloc (sizeof (int)); */
|
||||
s_v.subscripts = NULL;
|
||||
switch (facttok->kind)
|
||||
{
|
||||
|
||||
@ -2267,7 +2261,7 @@ factor(struct LOC_exec * LINK)
|
||||
|
||||
case tokdh_a:
|
||||
{
|
||||
if (PhreeqcPtr->llnl_count_temp > 0)
|
||||
if (PhreeqcPtr->llnl_temp.size() > 0)
|
||||
{
|
||||
n.UU.val = PhreeqcPtr->a_llnl;
|
||||
}
|
||||
@ -2293,7 +2287,7 @@ factor(struct LOC_exec * LINK)
|
||||
|
||||
case tokdh_b:
|
||||
{
|
||||
if (PhreeqcPtr->llnl_count_temp > 0)
|
||||
if (PhreeqcPtr->llnl_temp.size() > 0)
|
||||
{
|
||||
n.UU.val = PhreeqcPtr->b_llnl;
|
||||
}
|
||||
@ -2414,8 +2408,8 @@ factor(struct LOC_exec * LINK)
|
||||
PhreeqcPtr->sys_tot = 0;
|
||||
//PhreeqcPtr->count_sys = 1000;
|
||||
//int count_sys = PhreeqcPtr->count_sys;
|
||||
int count_sys = 1000;
|
||||
names_arg = (char**)PhreeqcPtr->PHRQ_calloc(((size_t)count_sys + 1), sizeof(char*));
|
||||
size_t count_sys = 1000;
|
||||
names_arg = (char**)PhreeqcPtr->PHRQ_calloc((count_sys + 1), sizeof(char*));
|
||||
if (names_arg == NULL)
|
||||
{
|
||||
PhreeqcPtr->malloc_error();
|
||||
@ -2423,7 +2417,7 @@ factor(struct LOC_exec * LINK)
|
||||
exit(4);
|
||||
#endif
|
||||
}
|
||||
moles_arg = (LDBLE*)PhreeqcPtr->PHRQ_calloc(((size_t)count_sys + 1), sizeof(LDBLE));
|
||||
moles_arg = (LDBLE*)PhreeqcPtr->PHRQ_calloc((count_sys + 1), sizeof(LDBLE));
|
||||
if (moles_arg == NULL)
|
||||
{
|
||||
PhreeqcPtr->malloc_error();
|
||||
@ -2521,11 +2515,6 @@ factor(struct LOC_exec * LINK)
|
||||
LINK->t = LINK->t->next;
|
||||
require(tokrp, LINK);
|
||||
|
||||
// Make work space
|
||||
//int max_length = length < 256 ? 256 : length;
|
||||
//char *token = (char *) PhreeqcPtr->PHRQ_calloc(size_t (max_length + 1), sizeof(char));
|
||||
//if (token == NULL) PhreeqcPtr->malloc_error();
|
||||
|
||||
// set function value
|
||||
LDBLE eq;
|
||||
std::string elt_name;
|
||||
@ -2561,30 +2550,14 @@ factor(struct LOC_exec * LINK)
|
||||
|
||||
case tokexists:
|
||||
{
|
||||
std::ostringstream oss;
|
||||
require(toklp, LINK);
|
||||
|
||||
s_v.count_subscripts = 0;
|
||||
/* get first subscript */
|
||||
if (LINK->t != NULL && LINK->t->kind != tokrp)
|
||||
{
|
||||
i = intexpr(LINK);
|
||||
if (s_v.subscripts == NULL)
|
||||
{
|
||||
s_v.subscripts = (int*)PhreeqcPtr->PHRQ_malloc(sizeof(int));
|
||||
if (s_v.subscripts == NULL)
|
||||
PhreeqcPtr->malloc_error();
|
||||
}
|
||||
s_v.subscripts = (int*)PhreeqcPtr->PHRQ_realloc(s_v.subscripts,
|
||||
((size_t)s_v.count_subscripts + 1) * sizeof(int));
|
||||
if (s_v.subscripts == NULL)
|
||||
{
|
||||
PhreeqcPtr->malloc_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
s_v.subscripts[s_v.count_subscripts] = i;
|
||||
s_v.count_subscripts++;
|
||||
}
|
||||
oss << i << ",";
|
||||
}
|
||||
|
||||
/* get other subscripts */
|
||||
@ -2594,23 +2567,7 @@ factor(struct LOC_exec * LINK)
|
||||
{
|
||||
LINK->t = LINK->t->next;
|
||||
j = intexpr(LINK);
|
||||
if (s_v.subscripts == NULL)
|
||||
{
|
||||
s_v.subscripts = (int*)PhreeqcPtr->PHRQ_malloc(sizeof(int));
|
||||
if (s_v.subscripts == NULL)
|
||||
PhreeqcPtr->malloc_error();
|
||||
}
|
||||
s_v.subscripts = (int*)PhreeqcPtr->PHRQ_realloc(s_v.subscripts,
|
||||
((size_t)s_v.count_subscripts + 1) * sizeof(int));
|
||||
if (s_v.subscripts == NULL)
|
||||
{
|
||||
PhreeqcPtr->malloc_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
s_v.subscripts[s_v.count_subscripts] = j;
|
||||
s_v.count_subscripts++;
|
||||
}
|
||||
oss << j << ",";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2625,15 +2582,8 @@ factor(struct LOC_exec * LINK)
|
||||
}
|
||||
else
|
||||
{
|
||||
s_v_ptr = PhreeqcPtr->save_values_bsearch(&s_v, &k);
|
||||
if (s_v_ptr == NULL)
|
||||
{
|
||||
n.UU.val = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
n.UU.val = 1;
|
||||
}
|
||||
std::map<std::string, double>::iterator it = PhreeqcPtr->save_values.find(oss.str());
|
||||
n.UU.val = (it == PhreeqcPtr->save_values.end()) ? 0 : 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -2672,25 +2622,14 @@ factor(struct LOC_exec * LINK)
|
||||
|
||||
case tokget:
|
||||
{
|
||||
std::ostringstream oss;
|
||||
require(toklp, LINK);
|
||||
|
||||
s_v.count_subscripts = 0;
|
||||
/* get first subscript */
|
||||
if (LINK->t != NULL && LINK->t->kind != tokrp)
|
||||
{
|
||||
i = intexpr(LINK);
|
||||
if (s_v.subscripts == NULL)
|
||||
{
|
||||
s_v.subscripts = (int*)PhreeqcPtr->PHRQ_malloc(sizeof(int));
|
||||
if (s_v.subscripts == NULL)
|
||||
PhreeqcPtr->malloc_error();
|
||||
}
|
||||
s_v.subscripts = (int*)PhreeqcPtr->PHRQ_realloc(s_v.subscripts,
|
||||
((size_t)s_v.count_subscripts + 1) * sizeof(int));
|
||||
if (s_v.subscripts == NULL)
|
||||
PhreeqcPtr->malloc_error();
|
||||
s_v.subscripts[s_v.count_subscripts] = i;
|
||||
s_v.count_subscripts++;
|
||||
oss << i << ",";
|
||||
}
|
||||
|
||||
/* get other subscripts */
|
||||
@ -2700,18 +2639,7 @@ factor(struct LOC_exec * LINK)
|
||||
{
|
||||
LINK->t = LINK->t->next;
|
||||
j = intexpr(LINK);
|
||||
if (s_v.subscripts == NULL)
|
||||
{
|
||||
s_v.subscripts = (int*)PhreeqcPtr->PHRQ_malloc(sizeof(int));
|
||||
if (s_v.subscripts == NULL)
|
||||
PhreeqcPtr->malloc_error();
|
||||
}
|
||||
s_v.subscripts = (int*)PhreeqcPtr->PHRQ_realloc(s_v.subscripts,
|
||||
((size_t)s_v.count_subscripts + 1) * sizeof(int));
|
||||
if (s_v.subscripts == NULL)
|
||||
PhreeqcPtr->malloc_error();
|
||||
s_v.subscripts[s_v.count_subscripts] = j;
|
||||
s_v.count_subscripts++;
|
||||
oss << j << ",";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2720,14 +2648,14 @@ factor(struct LOC_exec * LINK)
|
||||
break;
|
||||
}
|
||||
}
|
||||
s_v_ptr = (parse_all) ? NULL : PhreeqcPtr->save_values_bsearch(&s_v, &k);
|
||||
if (s_v_ptr == NULL)
|
||||
if (parse_all)
|
||||
{
|
||||
n.UU.val = (parse_all) ? 1 : 0;
|
||||
n.UU.val = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
n.UU.val = s_v_ptr->value;
|
||||
std::map<std::string, double>::iterator it = PhreeqcPtr->save_values.find(oss.str());
|
||||
n.UU.val = (it == PhreeqcPtr->save_values.end()) ? 0 : it->second;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -2743,7 +2671,7 @@ factor(struct LOC_exec * LINK)
|
||||
{
|
||||
if (PhreeqcPtr->phast != TRUE)
|
||||
{
|
||||
if (i <= 0 || i > PhreeqcPtr->count_cells * (1 + PhreeqcPtr->stag_data->count_stag) + 1
|
||||
if (i <= 0 || i > PhreeqcPtr->count_cells * (1 + PhreeqcPtr->stag_data.count_stag) + 1
|
||||
|| i == PhreeqcPtr->count_cells + 1)
|
||||
{
|
||||
/* warning_msg("Note... no porosity for boundary solutions."); */
|
||||
@ -3642,7 +3570,7 @@ factor(struct LOC_exec * LINK)
|
||||
|
||||
// Make work space
|
||||
int max_length = length < 256 ? 256 : length;
|
||||
char* token = (char*)PhreeqcPtr->PHRQ_calloc(((size_t)max_length + 1), sizeof(char));
|
||||
char* token = (char*)PhreeqcPtr->PHRQ_calloc((max_length + 1), sizeof(char));
|
||||
if (token == NULL) PhreeqcPtr->malloc_error();
|
||||
|
||||
std::string std_num;
|
||||
@ -3685,7 +3613,7 @@ factor(struct LOC_exec * LINK)
|
||||
|
||||
// Make work space
|
||||
int max_length = length < 256 ? 256 : length;
|
||||
char* token = (char*)PhreeqcPtr->PHRQ_calloc(((size_t)max_length + 1), sizeof(char));
|
||||
char* token = (char*)PhreeqcPtr->PHRQ_calloc((max_length + 1), sizeof(char));
|
||||
if (token == NULL) PhreeqcPtr->malloc_error();
|
||||
|
||||
std::string std_num;
|
||||
@ -4312,7 +4240,6 @@ factor(struct LOC_exec * LINK)
|
||||
snerr(": missing \" or (");
|
||||
break;
|
||||
}
|
||||
s_v.subscripts = (int *) PhreeqcPtr->free_check_null(s_v.subscripts);
|
||||
return n;
|
||||
}
|
||||
|
||||
@ -4876,16 +4803,13 @@ void PBasic::
|
||||
cmdput(struct LOC_exec *LINK)
|
||||
{
|
||||
int j;
|
||||
struct save_values s_v;
|
||||
|
||||
s_v.count_subscripts = 0;
|
||||
s_v.subscripts = (int *) PhreeqcPtr->PHRQ_malloc(sizeof(int));
|
||||
std::ostringstream oss;
|
||||
|
||||
/* get parentheses */
|
||||
require(toklp, LINK);
|
||||
|
||||
/* get first argumen */
|
||||
s_v.value = realexpr(LINK);
|
||||
double value = realexpr(LINK);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
@ -4893,14 +4817,7 @@ cmdput(struct LOC_exec *LINK)
|
||||
{
|
||||
LINK->t = LINK->t->next;
|
||||
j = intexpr(LINK);
|
||||
s_v.count_subscripts++;
|
||||
s_v.subscripts =
|
||||
(int *) PhreeqcPtr->PHRQ_realloc(s_v.subscripts,
|
||||
(size_t) s_v.count_subscripts *
|
||||
sizeof(int));
|
||||
if (s_v.subscripts == NULL)
|
||||
PhreeqcPtr->malloc_error();
|
||||
s_v.subscripts[s_v.count_subscripts - 1] = j;
|
||||
oss << j << ",";
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -4911,9 +4828,8 @@ cmdput(struct LOC_exec *LINK)
|
||||
}
|
||||
if (!parse_all)
|
||||
{
|
||||
PhreeqcPtr->save_values_store(&s_v);
|
||||
PhreeqcPtr->save_values[oss.str()] = value;
|
||||
}
|
||||
s_v.subscripts = (int *) PhreeqcPtr->free_check_null(s_v.subscripts);
|
||||
}
|
||||
|
||||
void PBasic::
|
||||
@ -4928,7 +4844,7 @@ cmdchange_por(struct LOC_exec *LINK)
|
||||
/* get cell_no */
|
||||
j = intexpr(LINK);
|
||||
require(tokrp, LINK);
|
||||
if (j > 0 && j <= PhreeqcPtr->count_cells * (1 + PhreeqcPtr->stag_data->count_stag) + 1
|
||||
if (j > 0 && j <= PhreeqcPtr->count_cells * (1 + PhreeqcPtr->stag_data.count_stag) + 1
|
||||
&& j != PhreeqcPtr->count_cells + 1)
|
||||
PhreeqcPtr->cell_data[j].por = TEMP;
|
||||
}
|
||||
|
||||
@ -473,11 +473,11 @@ public:
|
||||
void cmddim(struct LOC_exec *LINK);
|
||||
void cmderase(struct LOC_exec *LINK);
|
||||
void cmdpoke(struct LOC_exec *LINK);
|
||||
int basic_main(char *commands);
|
||||
int basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase);
|
||||
int basic_main(const char *commands);
|
||||
int basic_compile(const char *commands, void **lnbase, void **vbase, void **lpbase);
|
||||
int basic_run(char *commands, void *lnbase, void *vbase, void *lpbase);
|
||||
int basic_init(void);
|
||||
int sget_logical_line(char **ptr, int *l, char *return_line);
|
||||
int sget_logical_line(const char **ptr, int *l, char *return_line);
|
||||
long my_labs(long x);
|
||||
void * my_memmove(void * d, Const void * s, size_t n);
|
||||
void * my_memcpy(void * d, Const void * s, size_t n);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
1333
phreeqcpp/Phreeqc.h
1333
phreeqcpp/Phreeqc.h
File diff suppressed because it is too large
Load Diff
@ -15,7 +15,7 @@ UserPunch::~UserPunch(void)
|
||||
if (this->PhreeqcPtr != NULL)
|
||||
{
|
||||
this->PhreeqcPtr->rate_free(this->rate);
|
||||
this->PhreeqcPtr->free_check_null(this->rate);
|
||||
delete this->rate;
|
||||
}
|
||||
}
|
||||
this->PhreeqcPtr = NULL;
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
#include "cxxKinetics.h"
|
||||
#include "Solution.h"
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
advection(void)
|
||||
@ -60,7 +59,7 @@ advection(void)
|
||||
/*
|
||||
* Equilibrate solutions with phases, exchangers, surfaces
|
||||
*/
|
||||
last_model.force_prep = TRUE;
|
||||
last_model.force_prep = true;
|
||||
rate_sim_time_start = 0;
|
||||
for (advection_step = 1; advection_step <= count_ad_shifts;
|
||||
advection_step++)
|
||||
@ -89,7 +88,7 @@ advection(void)
|
||||
/*
|
||||
* Equilibrate and (or) mix
|
||||
*/
|
||||
for (i = 1; i <= count_ad_cells; i++)
|
||||
for (int i = 1; i <= count_ad_cells; i++)
|
||||
{
|
||||
set_initial_moles(i);
|
||||
cell_no = i;
|
||||
@ -102,17 +101,17 @@ advection(void)
|
||||
log_msg(sformatf( "\nCell %d.\n\n", i));
|
||||
if (pr.use == TRUE && pr.all == TRUE &&
|
||||
advection_step % print_ad_modulus == 0 &&
|
||||
advection_print[i - 1] == TRUE)
|
||||
advection_print[(size_t)i - 1] == TRUE)
|
||||
{
|
||||
output_msg(sformatf( "\nCell %d.\n\n", i));
|
||||
}
|
||||
if (advection_step % punch_ad_modulus == 0 &&
|
||||
advection_punch[i - 1] == TRUE)
|
||||
advection_punch[(size_t)i - 1] == TRUE)
|
||||
{
|
||||
punch_all();
|
||||
}
|
||||
if (advection_step % print_ad_modulus == 0 &&
|
||||
advection_print[i - 1] == TRUE)
|
||||
advection_print[(size_t)i - 1] == TRUE)
|
||||
{
|
||||
print_all();
|
||||
}
|
||||
|
||||
@ -644,15 +644,15 @@ calc_logk_p(const char *name)
|
||||
|
||||
if (phase_ptr != NULL)
|
||||
{
|
||||
struct reaction *reaction_ptr;
|
||||
CReaction* reaction_ptr;
|
||||
if (phase_ptr->replaced)
|
||||
reaction_ptr = phase_ptr->rxn_s;
|
||||
reaction_ptr = &phase_ptr->rxn_s;
|
||||
else
|
||||
reaction_ptr = phase_ptr->rxn;
|
||||
reaction_ptr = &phase_ptr->rxn;
|
||||
/*
|
||||
* Print saturation index
|
||||
*/
|
||||
reaction_ptr->logk[delta_v] = calc_delta_v(reaction_ptr, true) -
|
||||
reaction_ptr->logk[delta_v] = calc_delta_v(*reaction_ptr, true) -
|
||||
phase_ptr->logk[vm0];
|
||||
if (reaction_ptr->logk[delta_v])
|
||||
mu_terms_in_logk = true;
|
||||
@ -684,7 +684,7 @@ calc_logk_s(const char *name)
|
||||
{
|
||||
//if (s_ptr->logk[vm_tc])
|
||||
/* calculate delta_v for the reaction... */
|
||||
s_ptr->logk[delta_v] = calc_delta_v(s_ptr->rxn, false);
|
||||
s_ptr->logk[delta_v] = calc_delta_v(*&s_ptr->rxn, false);
|
||||
for (i = 0; i < MAX_LOG_K_INDICES; i++)
|
||||
{
|
||||
l_logk[i] = 0.0;
|
||||
@ -722,7 +722,7 @@ dh_bdot(const char* name)
|
||||
char token[MAX_LENGTH];
|
||||
struct species* s_ptr;
|
||||
double b = -999.99;
|
||||
if (llnl_count_temp > 0)
|
||||
if (llnl_temp.size() > 0)
|
||||
{
|
||||
b = bdot_llnl;
|
||||
}
|
||||
@ -753,15 +753,15 @@ calc_deltah_p(const char* name)
|
||||
|
||||
if (phase_ptr != NULL)
|
||||
{
|
||||
struct reaction* reaction_ptr;
|
||||
CReaction* reaction_ptr;
|
||||
if (phase_ptr->replaced)
|
||||
reaction_ptr = phase_ptr->rxn_s;
|
||||
reaction_ptr = &phase_ptr->rxn_s;
|
||||
else
|
||||
reaction_ptr = phase_ptr->rxn;
|
||||
reaction_ptr = &phase_ptr->rxn;
|
||||
/*
|
||||
* Print saturation index
|
||||
*/
|
||||
reaction_ptr->logk[delta_v] = calc_delta_v(reaction_ptr, true) -
|
||||
reaction_ptr->logk[delta_v] = calc_delta_v(*reaction_ptr, true) -
|
||||
phase_ptr->logk[vm0];
|
||||
if (reaction_ptr->logk[delta_v])
|
||||
mu_terms_in_logk = true;
|
||||
@ -793,7 +793,7 @@ calc_deltah_s(const char* name)
|
||||
if (s_ptr != NULL)
|
||||
{
|
||||
/* calculate delta_v for the reaction... */
|
||||
s_ptr->logk[delta_v] = calc_delta_v(s_ptr->rxn, false);
|
||||
s_ptr->logk[delta_v] = calc_delta_v(*&s_ptr->rxn, false);
|
||||
for (i = 0; i < MAX_LOG_K_INDICES; i++)
|
||||
{
|
||||
l_logk[i] = 0.0;
|
||||
@ -814,7 +814,7 @@ calc_surface_charge(const char *surface_name)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
char token[MAX_LENGTH], token1[MAX_LENGTH];
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
int i, j, k;
|
||||
LDBLE charge;
|
||||
struct rxn_token_temp *token_ptr;
|
||||
@ -831,7 +831,7 @@ calc_surface_charge(const char *surface_name)
|
||||
* Match surface_name
|
||||
*/
|
||||
count_trxn = 0;
|
||||
trxn_add(s_x[k]->rxn_s, 1.0, FALSE); /* rxn_s is set in tidy_model */
|
||||
trxn_add(s_x[k]->rxn_s, 1.0, false); /* rxn_s is set in tidy_model */
|
||||
for (i = 1; i < count_trxn; i++)
|
||||
{
|
||||
token_ptr = &(trxn.token[i]);
|
||||
@ -840,8 +840,8 @@ calc_surface_charge(const char *surface_name)
|
||||
master_ptr = trxn.token[i].s->primary;
|
||||
strcpy(token, master_ptr->elt->name);
|
||||
replace("_", " ", token);
|
||||
ptr = token;
|
||||
copy_token(token1, &ptr, &j);
|
||||
cptr = token;
|
||||
copy_token(token1, &cptr, &j);
|
||||
if (strcmp(surface_name, token1) == 0)
|
||||
{
|
||||
charge += s_x[k]->moles * s_x[k]->z;
|
||||
@ -1288,9 +1288,9 @@ equivalent_fraction(const char *name, LDBLE *eq, std::string &elt_name)
|
||||
if (s_ptr != NULL && (s_ptr->type == EX || s_ptr->type == SURF))
|
||||
{
|
||||
*eq = s_ptr->equiv;
|
||||
struct elt_list *next_elt;
|
||||
const struct elt_list *next_elt;
|
||||
LDBLE tot=0.0;
|
||||
for (next_elt = s_ptr->next_elt; next_elt->elt != NULL; next_elt++)
|
||||
for (next_elt = &s_ptr->next_elt[0]; next_elt->elt != NULL; next_elt++)
|
||||
{
|
||||
if (next_elt->elt->master->s->type == SURF ||
|
||||
next_elt->elt->master->s->type == EX)
|
||||
@ -1486,7 +1486,7 @@ get_calculate_value(const char *name)
|
||||
if (calculate_value_ptr->new_def == TRUE)
|
||||
{
|
||||
if (interp.basic_compile
|
||||
(calculate_value_ptr->commands,
|
||||
(calculate_value_ptr->commands.c_str(),
|
||||
&calculate_value_ptr->linebase,
|
||||
&calculate_value_ptr->varbase,
|
||||
&calculate_value_ptr->loopbase) != 0)
|
||||
@ -1735,7 +1735,7 @@ saturation_ratio(const char *phase_name)
|
||||
}
|
||||
else if (phase_ptr->in != FALSE)
|
||||
{
|
||||
for (rxn_ptr = phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL;
|
||||
for (rxn_ptr = &phase_ptr->rxn_x.token[0] + 1; rxn_ptr->s != NULL;
|
||||
rxn_ptr++)
|
||||
{
|
||||
iap += rxn_ptr->s->la * rxn_ptr->coef;
|
||||
@ -1767,7 +1767,7 @@ saturation_index(const char *phase_name, LDBLE * iap, LDBLE * si)
|
||||
}
|
||||
else if (phase_ptr->in != FALSE)
|
||||
{
|
||||
for (rxn_ptr = phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL;
|
||||
for (rxn_ptr = &phase_ptr->rxn_x.token[0] + 1; rxn_ptr->s != NULL;
|
||||
rxn_ptr++)
|
||||
{
|
||||
*iap += rxn_ptr->s->la * rxn_ptr->coef;
|
||||
@ -1787,7 +1787,7 @@ sum_match_gases(const char *mytemplate, const char *name)
|
||||
{
|
||||
int i;
|
||||
LDBLE tot;
|
||||
struct elt_list *next_elt;
|
||||
const struct elt_list *next_elt;
|
||||
|
||||
if (use.Get_gas_phase_in() == FALSE || use.Get_gas_phase_ptr() == NULL)
|
||||
return (0);
|
||||
@ -1805,7 +1805,7 @@ sum_match_gases(const char *mytemplate, const char *name)
|
||||
}
|
||||
else
|
||||
{
|
||||
for (next_elt = phase_ptr->next_elt;
|
||||
for (next_elt = &phase_ptr->next_elt[0];
|
||||
next_elt->elt != NULL; next_elt++)
|
||||
{
|
||||
if (strcmp(next_elt->elt->name, name) == 0)
|
||||
@ -1827,7 +1827,7 @@ sum_match_species(const char *mytemplate, const char *name)
|
||||
{
|
||||
int i;
|
||||
LDBLE tot;
|
||||
struct elt_list *next_elt;
|
||||
const struct elt_list *next_elt;
|
||||
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
@ -1856,7 +1856,7 @@ sum_match_species(const char *mytemplate, const char *name)
|
||||
}
|
||||
else
|
||||
{
|
||||
for (next_elt = s_ptr->next_elt; next_elt->elt != NULL;
|
||||
for (next_elt = &s_ptr->next_elt[0]; next_elt->elt != NULL;
|
||||
next_elt++)
|
||||
{
|
||||
if (strcmp(next_elt->elt->name, name) == 0)
|
||||
@ -1878,7 +1878,7 @@ sum_match_ss(const char *mytemplate, const char *name)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
LDBLE tot;
|
||||
struct elt_list *next_elt;
|
||||
const struct elt_list *next_elt;
|
||||
|
||||
if (use.Get_ss_assemblage_in() == FALSE || use.Get_ss_assemblage_ptr() == NULL)
|
||||
return (0);
|
||||
@ -1905,7 +1905,7 @@ sum_match_ss(const char *mytemplate, const char *name)
|
||||
{
|
||||
int l;
|
||||
struct phase *phase_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &l, FALSE);
|
||||
for (next_elt = phase_ptr->next_elt; next_elt->elt != NULL; next_elt++)
|
||||
for (next_elt = &phase_ptr->next_elt[0]; next_elt->elt != NULL; next_elt++)
|
||||
{
|
||||
if (strcmp(next_elt->elt->name, name) == 0)
|
||||
{
|
||||
@ -1966,9 +1966,8 @@ match_elts_in_species(const char *name, const char *mytemplate)
|
||||
*/
|
||||
int i, i1, l, case_no, match;
|
||||
char c, c1;
|
||||
char *ptr, *ptr1;
|
||||
const char* cptr, *ptr1;
|
||||
LDBLE d;
|
||||
char element[MAX_LENGTH];
|
||||
char token[MAX_LENGTH], equal_list[MAX_LENGTH];
|
||||
char token1[MAX_LENGTH], template1[MAX_LENGTH], equal_list1[MAX_LENGTH];
|
||||
char str[2];
|
||||
@ -1993,11 +1992,11 @@ match_elts_in_species(const char *name, const char *mytemplate)
|
||||
replace("--", "-2", token);
|
||||
}
|
||||
|
||||
ptr = token;
|
||||
cptr = token;
|
||||
std::vector< std::pair<std::string, LDBLE> > match_vector;
|
||||
while ((c = *ptr) != '\0')
|
||||
while ((c = *cptr) != '\0')
|
||||
{
|
||||
c1 = *(ptr + 1);
|
||||
c1 = *(cptr + 1);
|
||||
str[0] = c;
|
||||
str[1] = '\0';
|
||||
/*
|
||||
@ -2008,11 +2007,12 @@ match_elts_in_species(const char *name, const char *mytemplate)
|
||||
/*
|
||||
* Get new element and subscript
|
||||
*/
|
||||
if (get_elt(&ptr, element, &l) == ERROR)
|
||||
std::string element;
|
||||
if (get_elt(&cptr, element, &l) == ERROR)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
if (get_num(&ptr, &d) == ERROR)
|
||||
if (get_num(&cptr, &d) == ERROR)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
@ -2023,7 +2023,7 @@ match_elts_in_species(const char *name, const char *mytemplate)
|
||||
{
|
||||
std::pair<std::string, LDBLE> pr(str, 1.0);
|
||||
match_vector.push_back(pr);
|
||||
ptr += 1;
|
||||
cptr += 1;
|
||||
}
|
||||
}
|
||||
/*
|
||||
@ -2031,8 +2031,8 @@ match_elts_in_species(const char *name, const char *mytemplate)
|
||||
*/
|
||||
strcpy(template1, mytemplate);
|
||||
squeeze_white(template1);
|
||||
ptr = template1;
|
||||
while (extract_bracket(&ptr, equal_list) == TRUE)
|
||||
cptr = template1;
|
||||
while (extract_bracket(&cptr, equal_list) == TRUE)
|
||||
{
|
||||
replace("{", "", equal_list);
|
||||
replace("}", "", equal_list);
|
||||
@ -2102,8 +2102,8 @@ match_elts_in_species(const char *name, const char *mytemplate)
|
||||
*/
|
||||
strcpy(template1, mytemplate);
|
||||
squeeze_white(template1);
|
||||
ptr = template1;
|
||||
while (extract_bracket(&ptr, equal_list) == TRUE)
|
||||
cptr = template1;
|
||||
while (extract_bracket(&cptr, equal_list) == TRUE)
|
||||
{
|
||||
strcpy(equal_list1, equal_list);
|
||||
replace("{", "", equal_list);
|
||||
@ -2124,7 +2124,7 @@ match_elts_in_species(const char *name, const char *mytemplate)
|
||||
}
|
||||
replace(equal_list1, elt_name.c_str(), template1);
|
||||
squeeze_white(template1);
|
||||
ptr = template1;
|
||||
cptr = template1;
|
||||
}
|
||||
/*
|
||||
* Compare string
|
||||
@ -2160,13 +2160,13 @@ match_elts_in_species(const char *name, const char *mytemplate)
|
||||
break;
|
||||
case 1:
|
||||
/* leading wild card */
|
||||
if ((ptr = strstr(token, template1)) == NULL)
|
||||
if ((cptr = strstr(token, template1)) == NULL)
|
||||
{
|
||||
match = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strcmp(ptr, template1) == 0)
|
||||
if (strcmp(cptr, template1) == 0)
|
||||
match = TRUE;
|
||||
}
|
||||
break;
|
||||
@ -2186,14 +2186,15 @@ match_elts_in_species(const char *name, const char *mytemplate)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
extract_bracket(char **string, char *bracket_string)
|
||||
extract_bracket(const char **string, char *bracket_string)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
char *ptr, *ptr1;
|
||||
const char* cptr;
|
||||
char *ptr1;
|
||||
|
||||
if ((ptr = strstr(*string, "{")) == NULL)
|
||||
if ((cptr = strstr(*string, "{")) == NULL)
|
||||
return (FALSE);
|
||||
strcpy(bracket_string, ptr);
|
||||
strcpy(bracket_string, cptr);
|
||||
if ((ptr1 = strstr(bracket_string, "}")) == NULL)
|
||||
{
|
||||
error_string = sformatf(
|
||||
@ -2272,8 +2273,8 @@ surf_total(const char *total_name, const char *surface_name)
|
||||
|
||||
//strcpy(token, s_x[j]->next_elt[i].elt->name);
|
||||
//replace("_", " ", token);
|
||||
//ptr = token;
|
||||
//copy_token(name, &ptr, &k);
|
||||
//cptr = token;
|
||||
//copy_token(name, &cptr, &k);
|
||||
token = s_x[j]->next_elt[i].elt->name;
|
||||
replace("_", " ", token);
|
||||
std::string::iterator b = token.begin();
|
||||
@ -2292,7 +2293,7 @@ surf_total(const char *total_name, const char *surface_name)
|
||||
struct rxn_token *rxn_ptr;
|
||||
if (s_x[j]->mole_balance == NULL)
|
||||
{
|
||||
for (rxn_ptr = s_x[j]->rxn_s->token + 1; rxn_ptr->s != NULL; rxn_ptr++)
|
||||
for (rxn_ptr = &s_x[j]->rxn_s.token[0] + 1; rxn_ptr->s != NULL; rxn_ptr++)
|
||||
{
|
||||
if (redox && rxn_ptr->s->secondary)
|
||||
{
|
||||
@ -2360,7 +2361,7 @@ surf_total_no_redox(const char *total_name, const char *surface_name)
|
||||
int i, j, k;
|
||||
char name[MAX_LENGTH], token[MAX_LENGTH];
|
||||
char surface_name_local[MAX_LENGTH];
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
|
||||
if (use.Get_surface_ptr() == NULL)
|
||||
return (0);
|
||||
@ -2374,8 +2375,8 @@ surf_total_no_redox(const char *total_name, const char *surface_name)
|
||||
continue;
|
||||
strcpy(token, x[j]->master[0]->elt->name);
|
||||
replace("_", " ", token);
|
||||
ptr = token;
|
||||
copy_token(name, &ptr, &k);
|
||||
cptr = token;
|
||||
copy_token(name, &cptr, &k);
|
||||
if (surface_name != NULL)
|
||||
{
|
||||
if (strcmp(name, surface_name) == 0)
|
||||
@ -2404,8 +2405,8 @@ surf_total_no_redox(const char *total_name, const char *surface_name)
|
||||
|
||||
strcpy(token, s_x[j]->next_elt[i].elt->name);
|
||||
replace("_", " ", token);
|
||||
ptr = token;
|
||||
copy_token(name, &ptr, &k);
|
||||
cptr = token;
|
||||
copy_token(name, &cptr, &k);
|
||||
if (strcmp(name, surface_name_local) == 0)
|
||||
{
|
||||
/*
|
||||
@ -2437,7 +2438,6 @@ total(const char *total_name)
|
||||
{
|
||||
struct master *master_ptr;
|
||||
LDBLE t;
|
||||
int i;
|
||||
|
||||
if (strcmp(total_name, "H") == 0)
|
||||
{
|
||||
@ -2483,7 +2483,7 @@ total(const char *total_name)
|
||||
else
|
||||
{
|
||||
t = 0;
|
||||
for (i = master_ptr->number + 1;
|
||||
for (size_t i = master_ptr->number + 1;
|
||||
(i < (int)master.size() && master[i]->elt->primary == master_ptr);
|
||||
i++)
|
||||
{
|
||||
@ -2507,7 +2507,6 @@ total_mole(const char *total_name)
|
||||
{
|
||||
struct master *master_ptr;
|
||||
LDBLE t;
|
||||
int i;
|
||||
|
||||
if (strcmp(total_name, "H") == 0)
|
||||
{
|
||||
@ -2553,8 +2552,8 @@ total_mole(const char *total_name)
|
||||
else
|
||||
{
|
||||
t = 0;
|
||||
for (i = master_ptr->number + 1;
|
||||
(i < (int)master.size() && master[i]->elt->primary == master_ptr);
|
||||
for (size_t i = master_ptr->number + 1;
|
||||
(i < master.size() && master[i]->elt->primary == master_ptr);
|
||||
i++)
|
||||
{
|
||||
t += master[i]->total;
|
||||
@ -2737,7 +2736,7 @@ system_total(const char *total_name, LDBLE * count, char ***names,
|
||||
else if (sys.size() > 1)
|
||||
{
|
||||
qsort(&sys[0], sys.size(),
|
||||
(size_t)sizeof(struct system_species), system_species_compare_name);
|
||||
sizeof(struct system_species), system_species_compare_name);
|
||||
}
|
||||
/*
|
||||
* malloc space
|
||||
@ -2820,10 +2819,8 @@ kinetics_formula(std::string kin_name, cxxNameDouble &stoichiometry)
|
||||
// add formula
|
||||
std::string name = it->first;
|
||||
LDBLE coef = it->second;
|
||||
char * temp_name = string_duplicate(name.c_str());
|
||||
char *ptr = temp_name;
|
||||
get_elts_in_species(&ptr, coef);
|
||||
free_check_null(temp_name);
|
||||
const char* cptr = &name[0];
|
||||
get_elts_in_species(&cptr, coef);
|
||||
}
|
||||
}
|
||||
formula.append(kin_name);
|
||||
@ -2897,7 +2894,7 @@ int Phreeqc::
|
||||
system_total_elements(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
int i, j;
|
||||
int i;
|
||||
LDBLE t;
|
||||
char name[MAX_LENGTH];
|
||||
struct master *master_ptr;
|
||||
@ -2972,7 +2969,7 @@ system_total_elements(void)
|
||||
else
|
||||
{
|
||||
t = 0;
|
||||
for (j = master_ptr->number + 1;
|
||||
for (size_t j = master_ptr->number + 1;
|
||||
master[j]->elt->primary == master_ptr; j++)
|
||||
{
|
||||
t += master[j]->total;
|
||||
@ -3027,7 +3024,7 @@ system_total_si(void)
|
||||
* Print saturation index
|
||||
*/
|
||||
iap = 0.0;
|
||||
for (rxn_ptr = phases[i]->rxn_x->token + 1; rxn_ptr->s != NULL;
|
||||
for (rxn_ptr = &phases[i]->rxn_x.token[0] + 1; rxn_ptr->s != NULL;
|
||||
rxn_ptr++)
|
||||
{
|
||||
iap += rxn_ptr->s->la * rxn_ptr->coef;
|
||||
@ -3496,7 +3493,7 @@ system_total_elt_secondary(const char *total_name)
|
||||
{
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
if (s_x[i]->next_secondary != NULL)
|
||||
if (s_x[i]->next_secondary.size() != 0)
|
||||
{
|
||||
add_elt_list(s_x[i]->next_secondary, s_x[i]->moles);
|
||||
}
|
||||
@ -3569,7 +3566,7 @@ system_total_elt_secondary(const char *total_name)
|
||||
{
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
if (s_x[i]->next_secondary != NULL)
|
||||
if (s_x[i]->next_secondary.size() != 0)
|
||||
{
|
||||
add_elt_list(s_x[i]->next_secondary, 1);
|
||||
}
|
||||
@ -3782,7 +3779,7 @@ solution_sum_secondary(const char *total_name)
|
||||
continue;
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
if (s_x[i]->next_secondary != NULL)
|
||||
if (s_x[i]->next_secondary.size() != 0)
|
||||
{
|
||||
add_elt_list(s_x[i]->next_secondary, s_x[i]->moles);
|
||||
}
|
||||
@ -3986,7 +3983,7 @@ iso_unit(const char *total_name)
|
||||
}
|
||||
|
||||
int Phreeqc::
|
||||
basic_compile(char *commands, void **lnbase, void **vbase, void **lpbase)
|
||||
basic_compile(const char *commands, void **lnbase, void **vbase, void **lpbase)
|
||||
{
|
||||
return this->basic_interpreter->basic_compile(commands, lnbase, vbase, lpbase);
|
||||
}
|
||||
@ -4001,6 +3998,7 @@ void Phreeqc::
|
||||
basic_free(void)
|
||||
{
|
||||
delete this->basic_interpreter;
|
||||
this->basic_interpreter = NULL;
|
||||
}
|
||||
|
||||
#if defined(SWIG) || defined(SWIG_IPHREEQC)
|
||||
|
||||
@ -188,13 +188,7 @@ cl1(int k, int l, int m, int n,
|
||||
output_msg(sformatf( "Set up phase 1 costs\n"));
|
||||
#endif
|
||||
/* Zero first row of cu and iu */
|
||||
//memcpy((void *) &(l_cu[0]), (void *) &(scratch[0]),
|
||||
// (size_t) nklm * sizeof(LDBLE));
|
||||
memset(&l_cu[0], 0, (size_t)nklm * sizeof(LDBLE));
|
||||
//for (j = 0; j < nklm; ++j)
|
||||
//{
|
||||
// l_iu[j] = 0;
|
||||
//}
|
||||
memset(&l_iu[0], 0, (size_t)nklm * sizeof(int));
|
||||
/* L40: */
|
||||
#ifdef DEBUG_CL1
|
||||
|
||||
@ -135,11 +135,10 @@ main_method(int argc, char *argv[])
|
||||
{
|
||||
return errors;
|
||||
}
|
||||
Phreeqc MyCopy;
|
||||
MyCopy = *this;
|
||||
Phreeqc MyCopy = *this;
|
||||
this->clean_up();
|
||||
this->init();
|
||||
this->initialize();
|
||||
//this->init();
|
||||
//this->initialize();
|
||||
/*
|
||||
* Read input data for simulation
|
||||
*/
|
||||
@ -158,7 +157,7 @@ main_method(int argc, char *argv[])
|
||||
* Display successful status
|
||||
*/
|
||||
pr.headings = TRUE;
|
||||
errors = do_status();
|
||||
//errors = do_status();
|
||||
if (errors != 0)
|
||||
{
|
||||
return errors;
|
||||
@ -320,19 +319,17 @@ write_banner(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#ifdef ERROR_OSTREAM
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
process_file_names(int argc, char *argv[], std::istream **db_cookie,
|
||||
std::istream **input_cookie, int log)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
int l;
|
||||
char token[2 * MAX_LENGTH], default_name[2 * MAX_LENGTH];
|
||||
char query[2 * MAX_LENGTH];
|
||||
char in_file[2 * MAX_LENGTH], out_file[2 * MAX_LENGTH], db_file[2 * MAX_LENGTH];
|
||||
std::string token, default_name;
|
||||
std::string query;
|
||||
std::string in_file, out_file, db_file;
|
||||
char *env_ptr;
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
/*
|
||||
* Prepare error handling
|
||||
*/
|
||||
@ -365,28 +362,28 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
|
||||
/*
|
||||
* Open user-input file
|
||||
*/
|
||||
strcpy(query, "Name of input file?");
|
||||
query = "Name of input file?";
|
||||
std::ifstream * local_input_stream = NULL;
|
||||
if (argc <= 1)
|
||||
{
|
||||
default_name[0] = '\0';
|
||||
default_name.clear();
|
||||
local_input_stream = open_input_stream(query, default_name, std::ios_base::in, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(default_name, argv[1]);
|
||||
default_name = argv[1];
|
||||
local_input_stream = open_input_stream(query, default_name, std::ios_base::in, true);
|
||||
}
|
||||
screen_msg(sformatf("Input file: %s\n\n", default_name));
|
||||
strcpy(in_file, default_name);
|
||||
screen_msg(sformatf("Input file: %s\n\n", default_name.c_str()));
|
||||
in_file = default_name;
|
||||
/*
|
||||
* Open file for output
|
||||
*/
|
||||
strcpy(query, "Name of output file?");
|
||||
ptr = default_name;
|
||||
copy_token(token, &ptr, &l);
|
||||
strcpy(token, default_name);
|
||||
strcat(token, ".out");
|
||||
query = "Name of output file?";
|
||||
cptr = default_name.c_str();
|
||||
copy_token(token, &cptr);
|
||||
token = default_name;
|
||||
token.append(".out");
|
||||
std::ofstream * local_output_stream = NULL;
|
||||
if (argc <= 1)
|
||||
{
|
||||
@ -398,11 +395,11 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
|
||||
}
|
||||
else if (argc >= 3)
|
||||
{
|
||||
strcpy(token, argv[2]);
|
||||
token = argv[2];
|
||||
local_output_stream = open_output_stream(query, token, std::ios_base::out, true);
|
||||
}
|
||||
screen_msg(sformatf("Output file: %s\n\n", token));
|
||||
strcpy(out_file, token);
|
||||
screen_msg(sformatf("Output file: %s\n\n", token.c_str()));
|
||||
out_file = token;
|
||||
phrq_io->Set_output_ostream(local_output_stream);
|
||||
/*
|
||||
* Open log file
|
||||
@ -422,16 +419,15 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
|
||||
phrq_io->push_istream(local_input_stream);
|
||||
if (get_line() == KEYWORD)
|
||||
{
|
||||
ptr = line;
|
||||
copy_token(token, &ptr, &l);
|
||||
if (strcmp_nocase(token, "database") == 0)
|
||||
cptr = line;
|
||||
copy_token(token, &cptr);
|
||||
if (strcmp_nocase(token.c_str(), "database") == 0)
|
||||
{
|
||||
user_database = (char *) free_check_null(user_database);
|
||||
user_database = string_duplicate(ptr);
|
||||
if (string_trim(user_database) == EMPTY)
|
||||
user_database = cptr;
|
||||
string_trim(user_database);
|
||||
if (user_database.size() == 0)
|
||||
{
|
||||
warning_msg("DATABASE file name is missing; default database will be used.");
|
||||
user_database = (char *) free_check_null(user_database);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -440,26 +436,26 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
|
||||
else
|
||||
{
|
||||
delete local_input_stream;
|
||||
error_string = sformatf( "Error opening file, %s.", in_file);
|
||||
error_string = sformatf( "Error opening file, %s.", in_file.c_str());
|
||||
error_msg(error_string, STOP);
|
||||
}
|
||||
|
||||
/*
|
||||
* Open data base
|
||||
*/
|
||||
strcpy(query, "Name of database file?");
|
||||
query = "Name of database file?";
|
||||
env_ptr = getenv("PHREEQC_DATABASE");
|
||||
if (user_database != NULL)
|
||||
if (user_database.size() > 0)
|
||||
{
|
||||
strcpy(token, user_database);
|
||||
token = user_database;
|
||||
}
|
||||
else if (env_ptr != NULL)
|
||||
{
|
||||
strcpy(token, env_ptr);
|
||||
token = env_ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(token, default_data_base);
|
||||
token = default_data_base;
|
||||
}
|
||||
|
||||
std::ifstream * local_database_file = NULL;
|
||||
@ -473,9 +469,9 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
|
||||
}
|
||||
else if (argc >= 4)
|
||||
{
|
||||
if (user_database == NULL)
|
||||
if (user_database.size() == 0)
|
||||
{
|
||||
strcpy(token, argv[3]);
|
||||
token = argv[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -487,24 +483,21 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
|
||||
}
|
||||
local_database_file->close();
|
||||
delete local_database_file;
|
||||
|
||||
user_database = (char *) free_check_null(user_database);
|
||||
user_database = string_duplicate(token);
|
||||
screen_msg(sformatf("Database file: %s\n\n", token));
|
||||
strcpy(db_file, token);
|
||||
output_msg(sformatf(" Input file: %s\n", in_file));
|
||||
output_msg(sformatf(" Output file: %s\n", out_file));
|
||||
user_database = token;
|
||||
screen_msg(sformatf("Database file: %s\n\n", token.c_str()));
|
||||
db_file = token;
|
||||
output_msg(sformatf(" Input file: %s\n", in_file.c_str()));
|
||||
output_msg(sformatf(" Output file: %s\n", out_file.c_str()));
|
||||
#ifdef NPP
|
||||
output_msg(sformatf("Using PHREEQC: version 3.6.5, compiled February 24, 2021\n"));
|
||||
#endif
|
||||
output_msg(sformatf("Database file: %s\n\n", token));
|
||||
output_msg(sformatf("Database file: %s\n\n", token.c_str()));
|
||||
#ifdef NPP
|
||||
output_flush();
|
||||
#endif
|
||||
/*
|
||||
* local cleanup
|
||||
*/
|
||||
user_database = (char *) free_check_null(user_database);
|
||||
line = (char *) free_check_null(line);
|
||||
line_save = (char *) free_check_null(line_save);
|
||||
|
||||
@ -517,239 +510,38 @@ process_file_names(int argc, char *argv[], std::istream **db_cookie,
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
process_file_names(int argc, char *argv[], std::istream **db_cookie,
|
||||
std::istream **input_cookie, int log)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
int l;
|
||||
char token[2 * MAX_LENGTH], default_name[2 * MAX_LENGTH];
|
||||
char query[2 * MAX_LENGTH];
|
||||
char in_file[2 * MAX_LENGTH], out_file[2 * MAX_LENGTH], db_file[2 * MAX_LENGTH];
|
||||
char *env_ptr;
|
||||
char *ptr;
|
||||
/*
|
||||
* Prepare error handling
|
||||
*/
|
||||
try {
|
||||
if (phrq_io == NULL)
|
||||
{
|
||||
std::cerr << "No PHRQ_io output handler defined in process_file_names" << "\n";
|
||||
}
|
||||
/*
|
||||
* Prep for get_line
|
||||
*/
|
||||
max_line = MAX_LINE;
|
||||
space((void **) ((void *) &line), INIT, &max_line, sizeof(char));
|
||||
space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char));
|
||||
/*
|
||||
* Open error ostream
|
||||
*/
|
||||
if (argc > 4)
|
||||
{
|
||||
if (!phrq_io->error_open(argv[4]))
|
||||
{
|
||||
error_string = sformatf( "Error opening file, %s.", argv[4]);
|
||||
warning_msg(error_string);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
phrq_io->error_open(NULL);
|
||||
}
|
||||
/*
|
||||
* Open user-input file
|
||||
*/
|
||||
strcpy(query, "Name of input file?");
|
||||
std::ifstream * local_input_stream = NULL;
|
||||
if (argc <= 1)
|
||||
{
|
||||
default_name[0] = '\0';
|
||||
local_input_stream = open_input_stream(query, default_name, std::ios_base::in, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(default_name, argv[1]);
|
||||
local_input_stream = open_input_stream(query, default_name, std::ios_base::in, true);
|
||||
}
|
||||
screen_msg(sformatf("Input file: %s\n\n", default_name));
|
||||
strcpy(in_file, default_name);
|
||||
/*
|
||||
* Open file for output
|
||||
*/
|
||||
strcpy(query, "Name of output file?");
|
||||
ptr = default_name;
|
||||
copy_token(token, &ptr, &l);
|
||||
strcat(token, ".out");
|
||||
std::ofstream * local_output_stream;
|
||||
if (argc <= 1)
|
||||
{
|
||||
local_output_stream = open_output_stream(query, token, std::ios_base::out, false);
|
||||
}
|
||||
else if (argc == 2)
|
||||
{
|
||||
local_output_stream = open_output_stream(query, token, std::ios_base::out, true);
|
||||
}
|
||||
else if (argc >= 3)
|
||||
{
|
||||
strcpy(token, argv[2]);
|
||||
local_output_stream = open_output_stream(query, token, std::ios_base::out, true);
|
||||
}
|
||||
screen_msg(sformatf("Output file: %s\n\n", token));
|
||||
strcpy(out_file, token);
|
||||
phrq_io->Set_output_ostream(local_output_stream);
|
||||
/*
|
||||
* Open log file
|
||||
*/
|
||||
if (log == TRUE)
|
||||
{
|
||||
if (!phrq_io->log_open("phreeqc.log"))
|
||||
{
|
||||
error_msg("Cannot open log file, phreeqc.log.", STOP);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Read input file for DATABASE keyword
|
||||
*/
|
||||
if (local_input_stream->is_open())
|
||||
{
|
||||
phrq_io->push_istream(local_input_stream);
|
||||
if (get_line() == KEYWORD)
|
||||
{
|
||||
ptr = line;
|
||||
copy_token(token, &ptr, &l);
|
||||
if (strcmp_nocase(token, "database") == 0)
|
||||
{
|
||||
user_database = (char *) free_check_null(user_database);
|
||||
user_database = string_duplicate(ptr);
|
||||
if (string_trim(user_database) == EMPTY)
|
||||
{
|
||||
warning_msg("DATABASE file name is missing; default database will be used.");
|
||||
user_database = (char *) free_check_null(user_database);
|
||||
}
|
||||
}
|
||||
}
|
||||
phrq_io->pop_istream();
|
||||
}
|
||||
else
|
||||
{
|
||||
delete local_input_stream;
|
||||
error_string = sformatf( "Error opening file, %s.", in_file);
|
||||
error_msg(error_string, STOP);
|
||||
}
|
||||
|
||||
/*
|
||||
* Open data base
|
||||
*/
|
||||
strcpy(query, "Name of database file?");
|
||||
env_ptr = getenv("PHREEQC_DATABASE");
|
||||
if (user_database != NULL)
|
||||
{
|
||||
strcpy(token, user_database);
|
||||
}
|
||||
else if (env_ptr != NULL)
|
||||
{
|
||||
strcpy(token, env_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(token, default_data_base);
|
||||
}
|
||||
|
||||
std::ifstream * local_database_file;
|
||||
if (argc <= 1)
|
||||
{
|
||||
local_database_file = open_input_stream(query, token, std::ios_base::in, false);
|
||||
}
|
||||
else if (argc < 4)
|
||||
{
|
||||
local_database_file = open_input_stream(query, token, std::ios_base::in, true);
|
||||
}
|
||||
else if (argc >= 4)
|
||||
{
|
||||
if (user_database == NULL)
|
||||
{
|
||||
strcpy(token, argv[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef PHREEQCI_GUI
|
||||
warning_msg ("Database file from DATABASE keyword is used; command line argument ignored.");
|
||||
#endif
|
||||
}
|
||||
local_database_file = open_input_stream(query, token, std::ios_base::in, true);
|
||||
}
|
||||
local_database_file->close();
|
||||
delete local_database_file;
|
||||
screen_msg(sformatf("Database file: %s\n\n", token));
|
||||
strcpy(db_file, token);
|
||||
|
||||
output_msg(sformatf(" Input file: %s\n", in_file));
|
||||
output_msg(sformatf(" Output file: %s\n", out_file));
|
||||
output_msg(sformatf("Database file: %s\n\n", token));
|
||||
/*
|
||||
* local cleanup
|
||||
*/
|
||||
user_database = (char *) free_check_null(user_database);
|
||||
user_database = string_duplicate(token);
|
||||
line = (char *) free_check_null(line);
|
||||
line_save = (char *) free_check_null(line_save);
|
||||
|
||||
*db_cookie = new std::ifstream(db_file, std::ios_base::in);
|
||||
*input_cookie = new std::ifstream(in_file, std::ios_base::in);
|
||||
}
|
||||
catch (const PhreeqcStop& e)
|
||||
{
|
||||
return get_input_errors();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
/* ---------------------------------------------------------------------- */
|
||||
std::ifstream * Phreeqc::
|
||||
open_input_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch)
|
||||
open_input_stream(std::string query, std::string& default_name, std::ios_base::openmode mode, bool batch)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
char name[MAX_LENGTH];
|
||||
std::string name;
|
||||
std::ifstream *new_stream;
|
||||
int l;
|
||||
#ifdef ERROR_OSTREAM
|
||||
std::ostream * error_ostream_save = phrq_io->Get_error_ostream();
|
||||
#else
|
||||
FILE * error_file_save = phrq_io->Get_error_file();
|
||||
#endif
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/*
|
||||
* Get file name
|
||||
*/
|
||||
strcpy(name, default_name);
|
||||
name = default_name;
|
||||
if (!batch )
|
||||
{
|
||||
#ifdef ERROR_OSTREAM
|
||||
phrq_io->Set_error_ostream(&std::cerr);
|
||||
#else
|
||||
phrq_io->Set_error_file(stderr);
|
||||
#endif
|
||||
screen_msg(sformatf("%s\n", query));
|
||||
if (default_name[0] != '\0')
|
||||
screen_msg(sformatf("%s\n", query.c_str()));
|
||||
if (default_name.size() > 0)
|
||||
{
|
||||
screen_msg(sformatf("Default: %s\n", default_name));
|
||||
screen_msg(sformatf("Default: %s\n", default_name.c_str()));
|
||||
}
|
||||
char *s_ptr = fgets(name, MAX_LENGTH, stdin);
|
||||
if (s_ptr == NULL)
|
||||
std::getline(std::cin, name);
|
||||
if (name.size() == 0 && default_name.size() == 0)
|
||||
{
|
||||
std::cerr << "Failed defining name." << std::endl;
|
||||
std::cerr << "No name defined." << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
l = (int) strlen(name);
|
||||
name[l - 1] = '\0';
|
||||
if (name[0] == '\0')
|
||||
if (name.size() == 0)
|
||||
{
|
||||
strcpy(name, default_name);
|
||||
name = default_name;
|
||||
}
|
||||
}
|
||||
/*
|
||||
@ -758,15 +550,11 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode,
|
||||
new_stream = new std::ifstream(name, mode);
|
||||
if (new_stream == NULL || !new_stream->is_open())
|
||||
{
|
||||
#ifdef ERROR_OSTREAM
|
||||
phrq_io->Set_error_ostream(&std::cerr);
|
||||
#else
|
||||
phrq_io->Set_error_file(stderr);
|
||||
#endif
|
||||
error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name);
|
||||
error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name.c_str());
|
||||
screen_msg(error_string);
|
||||
#ifdef NPP
|
||||
error_msg(sformatf( "\nERROR: Cannot open file, %s.\n Please check, and give the correct, full path + name.\n", name), STOP);
|
||||
error_msg(sformatf( "\nERROR: Cannot open file, %s.\n Please check, and give the correct, full path + name.\n", name.c_str()), STOP);
|
||||
break;
|
||||
#endif
|
||||
error_flush();
|
||||
@ -775,62 +563,44 @@ open_input_stream(char *query, char *default_name, std::ios_base::openmode mode,
|
||||
}
|
||||
break;
|
||||
}
|
||||
strncpy(default_name, name, MAX_LENGTH);
|
||||
default_name = name;
|
||||
if (!batch )
|
||||
{
|
||||
//phrq_io->Set_error_ostream(error_file_save);
|
||||
#ifdef ERROR_OSTREAM
|
||||
phrq_io->Set_error_ostream(error_ostream_save);
|
||||
#else
|
||||
phrq_io->Set_error_file(error_file_save);
|
||||
#endif
|
||||
}
|
||||
return (new_stream);
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
std::ofstream * Phreeqc::
|
||||
open_output_stream(char *query, char *default_name, std::ios_base::openmode mode, bool batch)
|
||||
open_output_stream(std::string query, std::string& default_name, std::ios_base::openmode mode, bool batch)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
char name[MAX_LENGTH];
|
||||
std::string name;
|
||||
std::ofstream *new_stream;
|
||||
int l;
|
||||
#ifdef ERROR_OSTREAM
|
||||
std::ostream * error_ostream_save = phrq_io->Get_error_ostream();
|
||||
#else
|
||||
FILE * error_file_save = phrq_io->Get_error_file();
|
||||
#endif
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/*
|
||||
* Get file name
|
||||
*/
|
||||
strcpy(name, default_name);
|
||||
name = default_name;
|
||||
if (!batch )
|
||||
{
|
||||
#ifdef ERROR_OSTREAM
|
||||
phrq_io->Set_error_ostream(&std::cerr);
|
||||
#else
|
||||
phrq_io->Set_error_file(stderr);
|
||||
#endif
|
||||
|
||||
screen_msg(sformatf("%s\n", query));
|
||||
screen_msg(sformatf("%s\n", query.c_str()));
|
||||
if (default_name[0] != '\0')
|
||||
{
|
||||
screen_msg(sformatf("Default: %s\n", default_name));
|
||||
screen_msg(sformatf("Default: %s\n", default_name.c_str()));
|
||||
}
|
||||
char *s_ptr = fgets(name, MAX_LENGTH, stdin);
|
||||
if (s_ptr == NULL)
|
||||
std::getline(std::cin, name);
|
||||
if (name.size() == 0 && default_name.size() == 0)
|
||||
{
|
||||
std::cerr << "Failed defining name." << std::endl;
|
||||
std::cerr << "No name defined." << std::endl;
|
||||
}
|
||||
|
||||
l = (int) strlen(name);
|
||||
name[l - 1] = '\0';
|
||||
if (name[0] == '\0')
|
||||
if (name.size() == 0)
|
||||
{
|
||||
strcpy(name, default_name);
|
||||
name = default_name;
|
||||
}
|
||||
}
|
||||
/*
|
||||
@ -839,12 +609,8 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode
|
||||
new_stream = new std::ofstream(name, mode);
|
||||
if (new_stream == NULL || !new_stream->is_open())
|
||||
{
|
||||
#ifdef ERROR_OSTREAM
|
||||
phrq_io->Set_error_ostream(&std::cerr);
|
||||
#else
|
||||
phrq_io->Set_error_file(stderr);
|
||||
#endif
|
||||
error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name);
|
||||
error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name.c_str());
|
||||
screen_msg(error_string);
|
||||
error_flush();
|
||||
batch = FALSE;
|
||||
@ -852,92 +618,10 @@ open_output_stream(char *query, char *default_name, std::ios_base::openmode mode
|
||||
}
|
||||
break;
|
||||
}
|
||||
strncpy(default_name, name, MAX_LENGTH);
|
||||
default_name = name;
|
||||
if (!batch )
|
||||
{
|
||||
#ifdef ERROR_OSTREAM
|
||||
phrq_io->Set_error_ostream(error_ostream_save);
|
||||
#else
|
||||
phrq_io->Set_error_file(error_file_save);
|
||||
#endif
|
||||
}
|
||||
return (new_stream);
|
||||
}
|
||||
#ifdef SKIP
|
||||
/* ---------------------------------------------------------------------- */
|
||||
std::ofstream * Phreeqc::
|
||||
open_output_file(char *query, char *default_name, std::ios_base::openmode mode, bool batch)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
char name[MAX_LENGTH];
|
||||
std::ofstream *new_stream;
|
||||
int l;
|
||||
#ifdef ERROR_OSTREAM
|
||||
std::ostream * error_ostream_save = phrq_io->Get_error_ostream();
|
||||
#else
|
||||
FILE * error_file_save = phrq_io->Get_error_file();
|
||||
#endif
|
||||
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/*
|
||||
* Get file name
|
||||
*/
|
||||
strcpy(name, default_name);
|
||||
if (!batch )
|
||||
{
|
||||
#ifdef ERROR_OSTREAM
|
||||
phrq_io->Set_error_ostream(&std::cerr);
|
||||
#else
|
||||
phrq_io->Set_error_file(stderr);
|
||||
#endif
|
||||
screen_msg(sformatf("%s\n", query));
|
||||
if (default_name[0] != '\0')
|
||||
{
|
||||
screen_msg(sformatf("Default: %s\n", default_name));
|
||||
}
|
||||
char *s_ptr = fgets(name, MAX_LENGTH, stdin);
|
||||
if (s_ptr == NULL)
|
||||
{
|
||||
std::cerr << "Failed defining name." << std::endl;
|
||||
}
|
||||
|
||||
l = (int) strlen(name);
|
||||
name[l - 1] = '\0';
|
||||
if (name[0] == '\0')
|
||||
{
|
||||
strcpy(name, default_name);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Open existing file to read
|
||||
*/
|
||||
new_stream = new std::ofstream(name, mode);
|
||||
if (new_stream == NULL || !new_stream->is_open())
|
||||
{
|
||||
#ifdef ERROR_OSTREAM
|
||||
phrq_io->Set_error_ostream(&std::cerr);
|
||||
#else
|
||||
phrq_io->Set_error_file(stderr);
|
||||
#endif
|
||||
error_string = sformatf( "\nERROR: Cannot open file, %s.\n", name);
|
||||
screen_msg(error_string);
|
||||
error_flush();
|
||||
batch = FALSE;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
strncpy(default_name, name, MAX_LENGTH);
|
||||
if (!batch )
|
||||
{
|
||||
#ifdef ERROR_OSTREAM
|
||||
phrq_io->Set_error_ostream(error_ostream_save);
|
||||
#else
|
||||
phrq_io->Set_error_file(error_file_save);
|
||||
#endif
|
||||
}
|
||||
return (new_stream);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -56,7 +56,7 @@ build_fixed_volume_gas(void)
|
||||
* sum of partial pressures equation and
|
||||
* mass balance equations for elements contained in gases
|
||||
*/
|
||||
int row, col;
|
||||
size_t row, col;
|
||||
struct master *master_ptr;
|
||||
struct rxn_token *rxn_ptr;
|
||||
struct unknown *unknown_ptr;
|
||||
@ -75,7 +75,7 @@ build_fixed_volume_gas(void)
|
||||
*/
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
if (phase_ptr->rxn_x == NULL)
|
||||
if (phase_ptr->rxn_x.token.size() == 0)
|
||||
continue;
|
||||
add_elt_list(phase_ptr->next_elt, 1.0);
|
||||
#define COMBINE
|
||||
@ -174,7 +174,7 @@ build_fixed_volume_gas(void)
|
||||
}
|
||||
row = unknown_ptr->number * (count_unknowns + 1);
|
||||
coef_elt = elt_list[j].coef;
|
||||
for (rxn_ptr = phase_ptr->rxn_x->token + 1;
|
||||
for (rxn_ptr = &phase_ptr->rxn_x.token[0] + 1;
|
||||
rxn_ptr->s != NULL; rxn_ptr++)
|
||||
{
|
||||
|
||||
@ -246,7 +246,7 @@ build_fixed_volume_gas(void)
|
||||
}
|
||||
unknown_ptr = gas_unknown;
|
||||
row = unknown_ptr->number * (count_unknowns + 1);
|
||||
for (rxn_ptr = phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++)
|
||||
for (rxn_ptr = &phase_ptr->rxn_x.token[0] + 1; rxn_ptr->s != NULL; rxn_ptr++)
|
||||
{
|
||||
if (rxn_ptr->s != s_eminus && rxn_ptr->s->in == FALSE)
|
||||
{
|
||||
@ -648,8 +648,8 @@ calc_fixed_volume_gas_pressures(void)
|
||||
if (phase_ptr->in == TRUE)
|
||||
{
|
||||
lp = -phase_ptr->lk;
|
||||
//lp = -k_calc(phase_ptr->rxn_x->logk, tk_x, use.Get_gas_phase_ptr()->total_p * PASCAL_PER_ATM);
|
||||
for (rxn_ptr = phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL;
|
||||
//lp = -k_calc(phase_ptr->rxn_x.logk, tk_x, use.Get_gas_phase_ptr()->total_p * PASCAL_PER_ATM);
|
||||
for (rxn_ptr = &phase_ptr->rxn_x.token[0] + 1; rxn_ptr->s != NULL;
|
||||
rxn_ptr++)
|
||||
{
|
||||
lp += rxn_ptr->s->la * rxn_ptr->coef;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -298,21 +298,15 @@ polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, LDBLE * dy)
|
||||
{
|
||||
int i, m, ns;
|
||||
LDBLE den, dif, dift, ho, hp, w;
|
||||
LDBLE *c, *d;
|
||||
|
||||
ns = 1;
|
||||
dif = fabs(xv - xa[1]);
|
||||
/*
|
||||
* Malloc work space
|
||||
*/
|
||||
c = (LDBLE *) PHRQ_malloc(((size_t)n + 1) * sizeof(LDBLE));
|
||||
if (c == NULL)
|
||||
malloc_error();
|
||||
d = (LDBLE *) PHRQ_malloc(((size_t)n + 1) * sizeof(LDBLE));
|
||||
if (d == NULL)
|
||||
malloc_error();
|
||||
|
||||
|
||||
std::vector<double> c, d;
|
||||
c.resize((size_t)n + 1);
|
||||
d.resize((size_t)n + 1);
|
||||
|
||||
for (i = 1; i <= n; i++)
|
||||
{
|
||||
@ -329,7 +323,7 @@ polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, LDBLE * dy)
|
||||
*yv = ya[ns--];
|
||||
for (m = 1; m < n; m++)
|
||||
{
|
||||
for (i = 1; i <= n - m; i++)
|
||||
for (size_t i = 1; i <= n - m; i++)
|
||||
{
|
||||
ho = xa[i] - xv;
|
||||
hp = xa[i + m] - xv;
|
||||
@ -344,7 +338,7 @@ polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, LDBLE * dy)
|
||||
}
|
||||
if (2 * ns < (n - m))
|
||||
{
|
||||
*dy = c[ns + 1];
|
||||
*dy = c[(size_t)ns + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -354,8 +348,6 @@ polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, LDBLE * dy)
|
||||
|
||||
/* *yv += (*dy = (2 * ns < (n-m) ? c[ns+1] : d[ns--])); */
|
||||
}
|
||||
c = (LDBLE *) free_check_null(c);
|
||||
d = (LDBLE *) free_check_null(d);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -28,7 +28,7 @@ read_isotopes(void)
|
||||
struct element *elt_ptr;
|
||||
|
||||
int return_value, opt, opt_save;
|
||||
char *next_char;
|
||||
const char* next_char;
|
||||
const char *opt_list[] = {
|
||||
"isotope", /* 0 */
|
||||
"total_is_major" /* 1 */
|
||||
@ -160,25 +160,16 @@ read_calculate_values(void)
|
||||
* ERROR if error occurred reading data
|
||||
*
|
||||
*/
|
||||
char *ptr;
|
||||
int l, length, line_length;
|
||||
int l;
|
||||
int return_value, opt, opt_save;
|
||||
char token[MAX_LENGTH];
|
||||
struct calculate_value *calculate_value_ptr;
|
||||
char *description;
|
||||
int n_user, n_user_end;
|
||||
char *next_char;
|
||||
const char* next_char;
|
||||
const char *opt_list[] = {
|
||||
"start", /* 0 */
|
||||
"end" /* 1 */
|
||||
};
|
||||
int count_opt_list = 2;
|
||||
/*
|
||||
* Read advection number (not currently used)
|
||||
*/
|
||||
ptr = line;
|
||||
read_number_description(ptr, &n_user, &n_user_end, &description);
|
||||
description = (char *) free_check_null(description);
|
||||
opt_save = OPTION_DEFAULT;
|
||||
/*
|
||||
* Read lines
|
||||
@ -226,35 +217,19 @@ read_calculate_values(void)
|
||||
}
|
||||
calculate_value_ptr = calculate_value_store(token, TRUE);
|
||||
calculate_value_ptr->new_def = TRUE;
|
||||
calculate_value_ptr->commands =
|
||||
(char *) PHRQ_malloc(sizeof(char));
|
||||
if (calculate_value_ptr->commands == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
calculate_value_ptr->commands[0] = '\0';
|
||||
calculate_value_ptr->linebase = NULL;
|
||||
calculate_value_ptr->varbase = NULL;
|
||||
calculate_value_ptr->loopbase = NULL;
|
||||
}
|
||||
calculate_value_ptr->commands.clear();
|
||||
calculate_value_ptr->linebase = NULL;
|
||||
calculate_value_ptr->varbase = NULL;
|
||||
calculate_value_ptr->loopbase = NULL;
|
||||
opt_save = OPT_1;
|
||||
break;
|
||||
|
||||
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[length] = ';';
|
||||
calculate_value_ptr->commands[length + 1] = '\0';
|
||||
strcat((calculate_value_ptr->commands), line);
|
||||
opt_save = OPT_1;
|
||||
calculate_value_ptr->commands.append(";\0");
|
||||
calculate_value_ptr->commands.append(line);
|
||||
opt_save = OPT_1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -292,24 +267,15 @@ read_isotope_ratios(void)
|
||||
* ERROR if error occurred reading data
|
||||
*
|
||||
*/
|
||||
char *ptr;
|
||||
int l;
|
||||
int return_value, opt, opt_save;
|
||||
char token[MAX_LENGTH];
|
||||
struct isotope_ratio *isotope_ratio_ptr;
|
||||
char *description;
|
||||
int n_user, n_user_end;
|
||||
char *next_char;
|
||||
const char* next_char;
|
||||
const char *opt_list[] = {
|
||||
"no_options" /* 0 */
|
||||
};
|
||||
int count_opt_list = 0;
|
||||
/*
|
||||
* Read number (not currently used)
|
||||
*/
|
||||
ptr = line;
|
||||
read_number_description(ptr, &n_user, &n_user_end, &description);
|
||||
description = (char *) free_check_null(description);
|
||||
opt_save = OPTION_DEFAULT;
|
||||
/*
|
||||
* Read lines
|
||||
@ -391,24 +357,15 @@ read_isotope_alphas(void)
|
||||
* ERROR if error occurred reading data
|
||||
*
|
||||
*/
|
||||
char *ptr;
|
||||
int l;
|
||||
int return_value, opt, opt_save;
|
||||
char token[MAX_LENGTH];
|
||||
struct isotope_alpha *isotope_alpha_ptr;
|
||||
char *description;
|
||||
int n_user, n_user_end;
|
||||
char *next_char;
|
||||
const char* next_char;
|
||||
const char *opt_list[] = {
|
||||
"no_options" /* 0 */
|
||||
};
|
||||
int count_opt_list = 0;
|
||||
/*
|
||||
* Read number (not currently used)
|
||||
*/
|
||||
ptr = line;
|
||||
read_number_description(ptr, &n_user, &n_user_end, &description);
|
||||
description = (char *) free_check_null(description);
|
||||
opt_save = OPTION_DEFAULT;
|
||||
/*
|
||||
* Read lines
|
||||
@ -913,7 +870,7 @@ punch_calculate_values(void)
|
||||
if (calculate_value_ptr->new_def == TRUE)
|
||||
{
|
||||
if (basic_compile
|
||||
(calculate_value_ptr->commands, &calculate_value_ptr->linebase,
|
||||
(calculate_value_ptr->commands.c_str(), &calculate_value_ptr->linebase,
|
||||
&calculate_value_ptr->varbase,
|
||||
&calculate_value_ptr->loopbase) != 0)
|
||||
{
|
||||
@ -1146,7 +1103,7 @@ calculate_values(void)
|
||||
if (calculate_value_ptr->new_def == TRUE)
|
||||
{
|
||||
if (basic_compile
|
||||
(calculate_value_ptr->commands, &calculate_value_ptr->linebase,
|
||||
(calculate_value_ptr->commands.c_str(), &calculate_value_ptr->linebase,
|
||||
&calculate_value_ptr->varbase,
|
||||
&calculate_value_ptr->loopbase) != 0)
|
||||
{
|
||||
@ -1213,7 +1170,7 @@ calculate_values(void)
|
||||
if (calculate_value_ptr->new_def == TRUE)
|
||||
{
|
||||
if (basic_compile
|
||||
(calculate_value_ptr->commands, &calculate_value_ptr->linebase,
|
||||
(calculate_value_ptr->commands.c_str(), &calculate_value_ptr->linebase,
|
||||
&calculate_value_ptr->varbase,
|
||||
&calculate_value_ptr->loopbase) != 0)
|
||||
{
|
||||
@ -1304,11 +1261,11 @@ master_isotope_store(const char *name, int replace_if_found)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Function locates the string "name" in the hash table for master_isotope.
|
||||
* Function locates the string "name" in the map for master_isotope.
|
||||
*
|
||||
* Pointer to a master_isotope structure is always returned.
|
||||
*
|
||||
* If the string is not found, a new entry is made in the hash table. Pointer to
|
||||
* If the string is not found, a new entry is made in the map. Pointer to
|
||||
* the new structure is returned.
|
||||
* If "name" is found and replace is true, pointers in old master_isotope structure
|
||||
* are freed and replaced with additional input.
|
||||
@ -1532,7 +1489,7 @@ calculate_value_init(struct calculate_value *calculate_value_ptr)
|
||||
{
|
||||
calculate_value_ptr->name = NULL;
|
||||
calculate_value_ptr->value = 0.0;
|
||||
calculate_value_ptr->commands = NULL;
|
||||
calculate_value_ptr->commands.clear();
|
||||
calculate_value_ptr->new_def = TRUE;
|
||||
calculate_value_ptr->calculated = FALSE;
|
||||
calculate_value_ptr->linebase = NULL;
|
||||
@ -1583,8 +1540,7 @@ calculate_value_free(struct calculate_value *calculate_value_ptr)
|
||||
|
||||
if (calculate_value_ptr == NULL)
|
||||
return (ERROR);
|
||||
calculate_value_ptr->commands =
|
||||
(char *) free_check_null(calculate_value_ptr->commands);
|
||||
calculate_value_ptr->commands.clear();
|
||||
basic_run(cmd, calculate_value_ptr->linebase,
|
||||
calculate_value_ptr->varbase, calculate_value_ptr->loopbase);
|
||||
calculate_value_ptr->linebase = NULL;
|
||||
@ -1607,7 +1563,7 @@ isotope_ratio_store(const char *name_in, int replace_if_found)
|
||||
*
|
||||
* Pointer to a isotope_ratio structure is always returned.
|
||||
*
|
||||
* If the string is not found, a new entry is made in the hash table. Pointer to
|
||||
* If the string is not found, a new entry is made in the map. Pointer to
|
||||
* the new structure is returned.
|
||||
* If "name" is found and replace is true, pointers in old isotope_ratio structure
|
||||
* are freed and replaced with additional input.
|
||||
|
||||
@ -88,7 +88,7 @@ calc_kinetic_reaction(cxxKinetics *kinetics_ptr, LDBLE time_step)
|
||||
if (rate_ptr->new_def == TRUE)
|
||||
{
|
||||
if (basic_compile
|
||||
(rates[j].commands, &rates[j].linebase, &rates[j].varbase,
|
||||
(rates[j].commands.c_str(), &rates[j].linebase, &rates[j].varbase,
|
||||
&rates[j].loopbase) != 0)
|
||||
{
|
||||
error_string = sformatf( "Fatal Basic error in rate %s.",
|
||||
@ -186,14 +186,12 @@ RESTART: // if limiting rates, jump to here
|
||||
}
|
||||
else
|
||||
{
|
||||
char * temp_name = string_duplicate(name.c_str());
|
||||
char * ptr = temp_name;
|
||||
const char* ptr = name.c_str();
|
||||
if (get_elts_in_species(&ptr, coef * coef1) == ERROR)
|
||||
{
|
||||
error_string = sformatf("Error in -formula: %s", temp_name);
|
||||
error_string = sformatf("Error in -formula: %s", name.c_str());
|
||||
error_msg(error_string, CONTINUE);
|
||||
}
|
||||
free_check_null(temp_name);
|
||||
}
|
||||
}
|
||||
if (use.Get_exchange_ptr() != NULL
|
||||
@ -210,14 +208,13 @@ RESTART: // if limiting rates, jump to here
|
||||
name.c_str()) == 0)
|
||||
{
|
||||
/* found kinetics component */
|
||||
char * formula = string_duplicate(exchange_ptr->Get_exchange_comps()[j].Get_formula().c_str());
|
||||
char * ptr = formula;
|
||||
std::string formula = exchange_ptr->Get_exchange_comps()[j].Get_formula().c_str();
|
||||
const char* ptr = formula.c_str();
|
||||
if (get_elts_in_species(&ptr, -coef*exchange_ptr->Get_exchange_comps()[j].Get_phase_proportion()) == ERROR)
|
||||
{
|
||||
error_string = sformatf("Error in -formula: %s", formula);
|
||||
error_string = sformatf("Error in -formula: %s", formula.c_str());
|
||||
error_msg(error_string, CONTINUE);
|
||||
}
|
||||
free_check_null(formula);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -235,14 +232,13 @@ RESTART: // if limiting rates, jump to here
|
||||
surface_comp_ptr->Get_rate_name().c_str()) == 0)
|
||||
{
|
||||
/* found kinetics component */
|
||||
char * temp_formula = string_duplicate(surface_comp_ptr->Get_formula().c_str());
|
||||
char *ptr = temp_formula;
|
||||
std::string temp_formula = surface_comp_ptr->Get_formula().c_str();
|
||||
const char* cptr = temp_formula.c_str();
|
||||
/* Surface = 0 when m becomes low ...
|
||||
*/
|
||||
if (0.9 * surface_comp_ptr->Get_phase_proportion() *
|
||||
(kinetics_comp_ptr->Get_m()) < MIN_RELATED_SURFACE)
|
||||
{
|
||||
//master_ptr = master_bsearch(ptr);
|
||||
master_ptr = master_bsearch(surface_comp_ptr->Get_master_element().c_str());
|
||||
if (master_ptr != NULL)
|
||||
{
|
||||
@ -251,13 +247,12 @@ RESTART: // if limiting rates, jump to here
|
||||
}
|
||||
else
|
||||
{
|
||||
if (get_elts_in_species(&ptr, -coef * surface_comp_ptr->Get_phase_proportion()) == ERROR)
|
||||
if (get_elts_in_species(&cptr, -coef * surface_comp_ptr->Get_phase_proportion()) == ERROR)
|
||||
{
|
||||
error_string = sformatf("Error in -formula: %s", temp_formula);
|
||||
error_string = sformatf("Error in -formula: %s", temp_formula.c_str());
|
||||
error_msg(error_string, CONTINUE);
|
||||
}
|
||||
}
|
||||
free_check_null(temp_formula);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -324,7 +319,7 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver,
|
||||
/*
|
||||
* Save kinetics i and solution i, if necessary
|
||||
*/
|
||||
save_old = -2 - (count_cells * (1 + stag_data->count_stag) + 2);
|
||||
save_old = -2 - (count_cells * (1 + stag_data.count_stag) + 2);
|
||||
Utilities::Rxn_copy(Rxn_kinetics_map, i, save_old);
|
||||
if (nsaver != i)
|
||||
{
|
||||
@ -338,9 +333,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 +1105,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 +2033,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++)
|
||||
{
|
||||
@ -2077,7 +2064,7 @@ run_reactions(int i, LDBLE kin_time, int use_mix, LDBLE step_fraction)
|
||||
}
|
||||
else
|
||||
{
|
||||
save_old = -2 - (count_cells * (1 + stag_data->count_stag) + 2);
|
||||
save_old = -2 - (count_cells * (1 + stag_data.count_stag) + 2);
|
||||
if (nsaver != i)
|
||||
{
|
||||
Utilities::Rxn_copy(Rxn_solution_map, i, save_old);
|
||||
@ -2244,8 +2231,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 +2336,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 +2638,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 +2722,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 +2831,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 +2845,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 +2887,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 +2959,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 +2990,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;
|
||||
}
|
||||
|
||||
|
||||
@ -25,45 +25,23 @@ initialize(void)
|
||||
/*
|
||||
* Initialize global variables
|
||||
*/
|
||||
moles_per_kilogram_string = string_duplicate("Mol/kgw");
|
||||
pe_string = string_duplicate("pe");
|
||||
moles_per_kilogram_string = "Mol/kgw";
|
||||
/*
|
||||
* Allocate space
|
||||
*/
|
||||
cell_data_max_cells = count_cells + 2;
|
||||
space((void **) ((void *) &cell_data), INIT, &cell_data_max_cells,
|
||||
sizeof(struct cell_data));
|
||||
for (int i = 0; i < cell_data_max_cells; i++)
|
||||
{
|
||||
cell_data[i].length = 1.0;
|
||||
cell_data[i].mid_cell_x = 1.0;
|
||||
cell_data[i].disp = 1.0;
|
||||
cell_data[i].temp = 25.0;
|
||||
cell_data[i].por = 0.1;
|
||||
cell_data[i].por_il = 0.01;
|
||||
cell_data[i].potV = 0;
|
||||
cell_data[i].punch = FALSE;
|
||||
cell_data[i].print = FALSE;
|
||||
}
|
||||
cell_data.resize((size_t)count_cells + 2); // initialized by global_structures.h
|
||||
|
||||
count_inverse = 0;
|
||||
space((void **) ((void *) &line), INIT, &max_line, sizeof(char));
|
||||
|
||||
space((void **) ((void *) &line_save), INIT, &max_line, sizeof(char));
|
||||
|
||||
// one stag_data
|
||||
stag_data = (struct stag_data *) PHRQ_calloc(1, sizeof(struct stag_data));
|
||||
if (stag_data == NULL)
|
||||
malloc_error();
|
||||
stag_data->count_stag = 0;
|
||||
stag_data->exch_f = 0;
|
||||
stag_data->th_m = 0;
|
||||
stag_data->th_im = 0;
|
||||
// one stag_data in phreeqc.h, initialized in global_structures
|
||||
|
||||
// user_print
|
||||
user_print = (struct rate *) PHRQ_malloc((size_t) sizeof(struct rate));
|
||||
if (user_print == NULL)
|
||||
malloc_error();
|
||||
user_print->commands = NULL;
|
||||
user_print = new struct rate;
|
||||
user_print->name = string_hsave("User_print");
|
||||
user_print->commands.clear();
|
||||
user_print->linebase = NULL;
|
||||
user_print->varbase = NULL;
|
||||
user_print->loopbase = NULL;
|
||||
@ -71,27 +49,11 @@ initialize(void)
|
||||
Initialize llnl aqueous model parameters
|
||||
*/
|
||||
a_llnl = b_llnl = 0.0;
|
||||
llnl_temp = (LDBLE *) PHRQ_malloc(sizeof(LDBLE));
|
||||
if (llnl_temp == NULL)
|
||||
malloc_error();
|
||||
llnl_count_temp = 0;
|
||||
llnl_adh = (LDBLE *) PHRQ_malloc(sizeof(LDBLE));
|
||||
if (llnl_adh == NULL)
|
||||
malloc_error();
|
||||
llnl_count_adh = 0;
|
||||
llnl_bdh = (LDBLE *) PHRQ_malloc(sizeof(LDBLE));
|
||||
if (llnl_bdh == NULL)
|
||||
malloc_error();
|
||||
llnl_count_bdh = 0;
|
||||
llnl_bdot = (LDBLE *) PHRQ_malloc(sizeof(LDBLE));
|
||||
if (llnl_bdot == NULL)
|
||||
malloc_error();
|
||||
llnl_count_bdot = 0;
|
||||
llnl_co2_coefs = (LDBLE *) PHRQ_malloc(sizeof(LDBLE));
|
||||
if (llnl_co2_coefs == NULL)
|
||||
malloc_error();
|
||||
llnl_count_co2_coefs = 0;
|
||||
// new PBasic
|
||||
if (basic_interpreter != NULL)
|
||||
{
|
||||
basic_free();
|
||||
}
|
||||
basic_interpreter = new PBasic(this, phrq_io);
|
||||
// allocate one change_surf
|
||||
change_surf =
|
||||
@ -114,18 +76,6 @@ initialize(void)
|
||||
g_spread_sheet.defaults.iso = NULL;
|
||||
g_spread_sheet.defaults.redox = NULL;
|
||||
#endif
|
||||
// allocate space for copier
|
||||
copier_init(©_solution);
|
||||
copier_init(©_pp_assemblage);
|
||||
copier_init(©_exchange);
|
||||
copier_init(©_surface);
|
||||
copier_init(©_ss_assemblage);
|
||||
copier_init(©_gas_phase);
|
||||
copier_init(©_kinetics);
|
||||
copier_init(©_mix);
|
||||
copier_init(©_reaction);
|
||||
copier_init(©_temperature);
|
||||
copier_init(©_pressure);
|
||||
|
||||
// Initialize cvode
|
||||
cvode_init();
|
||||
@ -675,7 +625,7 @@ initial_gas_phases(int print)
|
||||
if (phase_ptr->in == TRUE)
|
||||
{
|
||||
lp = -phase_ptr->lk;
|
||||
for (rxn_ptr = phase_ptr->rxn_x->token + 1;
|
||||
for (rxn_ptr = &phase_ptr->rxn_x.token[0] + 1;
|
||||
rxn_ptr->s != NULL; rxn_ptr++)
|
||||
{
|
||||
lp += rxn_ptr->s->la * rxn_ptr->coef;
|
||||
@ -969,8 +919,7 @@ saver(void)
|
||||
if (save.solution == TRUE)
|
||||
{
|
||||
sprintf(token, "Solution after simulation %d.", simulation);
|
||||
description_x = (char *) free_check_null(description_x);
|
||||
description_x = string_duplicate(token);
|
||||
description_x = token;
|
||||
n = save.n_solution_user;
|
||||
xsolution_save(n);
|
||||
for (i = save.n_solution_user + 1; i <= save.n_solution_user_end; i++)
|
||||
@ -1884,286 +1833,164 @@ int Phreeqc::
|
||||
copy_entities(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
int i, j, return_value;
|
||||
int verbose;
|
||||
|
||||
verbose = FALSE;
|
||||
int return_value;
|
||||
return_value = OK;
|
||||
if (copy_solution.count > 0)
|
||||
for (size_t j = 0; j < copy_solution.n_user.size(); j++)
|
||||
{
|
||||
for (j = 0; j < copy_solution.count; j++)
|
||||
if (Utilities::Rxn_find(Rxn_solution_map, copy_solution.n_user[j]) != NULL)
|
||||
{
|
||||
if (Utilities::Rxn_find(Rxn_solution_map, copy_solution.n_user[j]) != NULL)
|
||||
for (size_t i = copy_solution.start[j]; i <= copy_solution.end[j]; i++)
|
||||
{
|
||||
for (i = copy_solution.start[j]; i <= copy_solution.end[j];
|
||||
i++)
|
||||
{
|
||||
if (i == copy_solution.n_user[j])
|
||||
continue;
|
||||
Utilities::Rxn_copy(Rxn_solution_map, copy_solution.n_user[j], i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (verbose == TRUE)
|
||||
{
|
||||
warning_msg("SOLUTION to copy not found.");
|
||||
return_value = ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (copy_pp_assemblage.count > 0)
|
||||
{
|
||||
for (j = 0; j < copy_pp_assemblage.count; j++)
|
||||
{
|
||||
if (Utilities::Rxn_find(Rxn_pp_assemblage_map, copy_pp_assemblage.n_user[j]) != NULL)
|
||||
{
|
||||
for (i = copy_pp_assemblage.start[j];
|
||||
i <= copy_pp_assemblage.end[j]; i++)
|
||||
{
|
||||
if (i == copy_pp_assemblage.n_user[j])
|
||||
continue;
|
||||
Utilities::Rxn_copy(Rxn_pp_assemblage_map, copy_pp_assemblage.n_user[j], i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (verbose == TRUE)
|
||||
{
|
||||
warning_msg("EQUILIBRIUM_PHASES to copy not found.");
|
||||
return_value = ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (copy_reaction.count > 0)
|
||||
{
|
||||
for (j = 0; j < copy_reaction.count; j++)
|
||||
{
|
||||
if (Utilities::Rxn_find(Rxn_reaction_map, copy_reaction.n_user[j]) != NULL)
|
||||
{
|
||||
for (i = copy_reaction.start[j]; i <= copy_reaction.end[j]; i++)
|
||||
{
|
||||
if (i == copy_reaction.n_user[j])
|
||||
continue;
|
||||
Utilities::Rxn_copy(Rxn_reaction_map, copy_reaction.n_user[j], i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (verbose == TRUE)
|
||||
{
|
||||
warning_msg("REACTION to copy not found.");
|
||||
return_value = ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (copy_mix.count > 0)
|
||||
{
|
||||
for (j = 0; j < copy_mix.count; j++)
|
||||
{
|
||||
if (Utilities::Rxn_find(Rxn_mix_map, copy_mix.n_user[j]) != NULL)
|
||||
{
|
||||
for (i = copy_mix.start[j]; i <= copy_mix.end[j]; i++)
|
||||
{
|
||||
if (i != copy_mix.n_user[j])
|
||||
{
|
||||
Utilities::Rxn_copy(Rxn_mix_map, copy_mix.n_user[j], i);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (verbose == TRUE)
|
||||
{
|
||||
warning_msg("Mix to copy not found.");
|
||||
return_value = ERROR;
|
||||
}
|
||||
if (i == copy_solution.n_user[j])
|
||||
continue;
|
||||
Utilities::Rxn_copy(Rxn_solution_map, copy_solution.n_user[j], (int)i);
|
||||
}
|
||||
}
|
||||
}
|
||||
copier_clear(©_solution);
|
||||
|
||||
if (copy_exchange.count > 0)
|
||||
for (size_t j = 0; j < copy_pp_assemblage.n_user.size(); j++)
|
||||
{
|
||||
for (j = 0; j < copy_exchange.count; j++)
|
||||
if (Utilities::Rxn_find(Rxn_pp_assemblage_map, copy_pp_assemblage.n_user[j]) != NULL)
|
||||
{
|
||||
if (Utilities::Rxn_find(Rxn_exchange_map, copy_exchange.n_user[j]) != NULL)
|
||||
for (size_t i = copy_pp_assemblage.start[j]; i <= copy_pp_assemblage.end[j]; i++)
|
||||
{
|
||||
for (i = copy_exchange.start[j]; i <= copy_exchange.end[j];
|
||||
i++)
|
||||
{
|
||||
if (i == copy_exchange.n_user[j])
|
||||
continue;
|
||||
Utilities::Rxn_copy(Rxn_exchange_map, copy_exchange.n_user[j], i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (verbose == TRUE)
|
||||
{
|
||||
warning_msg("EXCHANGE to copy not found.");
|
||||
return_value = ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (copy_surface.count > 0)
|
||||
{
|
||||
for (j = 0; j < copy_surface.count; j++)
|
||||
{
|
||||
if (Utilities::Rxn_find(Rxn_surface_map, copy_surface.n_user[j]) != NULL)
|
||||
{
|
||||
for (i = copy_surface.start[j]; i <= copy_surface.end[j]; i++)
|
||||
{
|
||||
if (i == copy_surface.n_user[j])
|
||||
continue;
|
||||
Utilities::Rxn_copy(Rxn_surface_map, copy_surface.n_user[j], i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (verbose == TRUE)
|
||||
{
|
||||
warning_msg("SURFACE to copy not found.");
|
||||
return_value = ERROR;
|
||||
}
|
||||
if (i == copy_pp_assemblage.n_user[j])
|
||||
continue;
|
||||
Utilities::Rxn_copy(Rxn_pp_assemblage_map, copy_pp_assemblage.n_user[j], (int)i);
|
||||
}
|
||||
}
|
||||
}
|
||||
copier_clear(©_pp_assemblage);
|
||||
|
||||
if (copy_temperature.count > 0)
|
||||
for (size_t j = 0; j < copy_reaction.n_user.size(); j++)
|
||||
{
|
||||
for (j = 0; j < copy_temperature.count; j++)
|
||||
if (Utilities::Rxn_find(Rxn_reaction_map, copy_reaction.n_user[j]) != NULL)
|
||||
{
|
||||
if (Utilities::Rxn_find(Rxn_temperature_map, copy_temperature.n_user[j]) != NULL)
|
||||
for (size_t i = copy_reaction.start[j]; i <= copy_reaction.end[j]; i++)
|
||||
{
|
||||
for (i = copy_temperature.start[j]; i <= copy_temperature.end[j]; i++)
|
||||
{
|
||||
if (i != copy_temperature.n_user[j])
|
||||
{
|
||||
Utilities::Rxn_copy(Rxn_temperature_map, copy_temperature.n_user[j], i);
|
||||
}
|
||||
}
|
||||
if (i == copy_reaction.n_user[j])
|
||||
continue;
|
||||
Utilities::Rxn_copy(Rxn_reaction_map, copy_reaction.n_user[j], (int)i);
|
||||
}
|
||||
else
|
||||
}
|
||||
}
|
||||
copier_clear(©_reaction);
|
||||
|
||||
for (size_t j = 0; j < copy_mix.n_user.size(); j++)
|
||||
{
|
||||
if (Utilities::Rxn_find(Rxn_mix_map, copy_mix.n_user[j]) != NULL)
|
||||
{
|
||||
for (size_t i = copy_mix.start[j]; i <= copy_mix.end[j]; i++)
|
||||
{
|
||||
if (verbose == TRUE)
|
||||
if (i != copy_mix.n_user[j])
|
||||
{
|
||||
warning_msg("temperature to copy not found.");
|
||||
return_value = ERROR;
|
||||
Utilities::Rxn_copy(Rxn_mix_map, copy_mix.n_user[j], (int)i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (copy_pressure.count > 0)
|
||||
copier_clear(©_mix);
|
||||
|
||||
for (size_t j = 0; j < copy_exchange.n_user.size(); j++)
|
||||
{
|
||||
for (j = 0; j < copy_pressure.count; j++)
|
||||
if (Utilities::Rxn_find(Rxn_exchange_map, copy_exchange.n_user[j]) != NULL)
|
||||
{
|
||||
if (Utilities::Rxn_find(Rxn_pressure_map, copy_pressure.n_user[j]) != NULL)
|
||||
for (size_t i = copy_exchange.start[j]; i <= copy_exchange.end[j]; i++)
|
||||
{
|
||||
for (i = copy_pressure.start[j]; i <= copy_pressure.end[j]; i++)
|
||||
{
|
||||
if (i != copy_pressure.n_user[j])
|
||||
{
|
||||
Utilities::Rxn_copy(Rxn_pressure_map, copy_pressure.n_user[j], i);
|
||||
}
|
||||
}
|
||||
if (i == copy_exchange.n_user[j]) continue;
|
||||
Utilities::Rxn_copy(Rxn_exchange_map, copy_exchange.n_user[j], (int)i);
|
||||
}
|
||||
else
|
||||
}
|
||||
}
|
||||
copier_clear(©_exchange);
|
||||
|
||||
for (size_t j = 0; j < copy_surface.n_user.size(); j++)
|
||||
{
|
||||
if (Utilities::Rxn_find(Rxn_surface_map, copy_surface.n_user[j]) != NULL)
|
||||
{
|
||||
for (size_t i = copy_surface.start[j]; i <= copy_surface.end[j]; i++)
|
||||
{
|
||||
if (verbose == TRUE)
|
||||
if (i == copy_surface.n_user[j])
|
||||
continue;
|
||||
Utilities::Rxn_copy(Rxn_surface_map, copy_surface.n_user[j], (int)i);
|
||||
}
|
||||
}
|
||||
}
|
||||
copier_clear(©_surface);
|
||||
|
||||
for (size_t j = 0; j < copy_temperature.n_user.size(); j++)
|
||||
{
|
||||
if (Utilities::Rxn_find(Rxn_temperature_map, copy_temperature.n_user[j]) != NULL)
|
||||
{
|
||||
for (size_t i = copy_temperature.start[j]; i <= copy_temperature.end[j]; i++)
|
||||
{
|
||||
if (i != copy_temperature.n_user[j])
|
||||
{
|
||||
warning_msg("pressure to copy not found.");
|
||||
return_value = ERROR;
|
||||
Utilities::Rxn_copy(Rxn_temperature_map, copy_temperature.n_user[j], (int)i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (copy_gas_phase.count > 0)
|
||||
copier_clear(©_temperature);
|
||||
|
||||
for (size_t j = 0; j < copy_pressure.n_user.size(); j++)
|
||||
{
|
||||
for (j = 0; j < copy_gas_phase.count; j++)
|
||||
if (Utilities::Rxn_find(Rxn_pressure_map, copy_pressure.n_user[j]) != NULL)
|
||||
{
|
||||
if (Utilities::Rxn_find(Rxn_gas_phase_map, copy_gas_phase.n_user[j]) != NULL)
|
||||
for (size_t i = copy_pressure.start[j]; i <= copy_pressure.end[j]; i++)
|
||||
{
|
||||
for (i = copy_gas_phase.start[j]; i <= copy_gas_phase.end[j];
|
||||
i++)
|
||||
if (i != copy_pressure.n_user[j])
|
||||
{
|
||||
if (i == copy_gas_phase.n_user[j])
|
||||
continue;
|
||||
Utilities::Rxn_copy(Rxn_gas_phase_map, copy_gas_phase.n_user[j], i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (verbose == TRUE)
|
||||
{
|
||||
warning_msg("EXCHANGE to copy not found.");
|
||||
return_value = ERROR;
|
||||
Utilities::Rxn_copy(Rxn_pressure_map, copy_pressure.n_user[j], (int)i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (copy_kinetics.count > 0)
|
||||
copier_clear(©_pressure);
|
||||
|
||||
for (size_t j = 0; j < copy_gas_phase.n_user.size(); j++)
|
||||
{
|
||||
for (j = 0; j < copy_kinetics.count; j++)
|
||||
if (Utilities::Rxn_find(Rxn_gas_phase_map, copy_gas_phase.n_user[j]) != NULL)
|
||||
{
|
||||
if (Utilities::Rxn_find(Rxn_kinetics_map, copy_kinetics.n_user[j]) != NULL)
|
||||
for (size_t i = copy_gas_phase.start[j]; i <= copy_gas_phase.end[j]; i++)
|
||||
{
|
||||
for (i = copy_kinetics.start[j]; i <= copy_kinetics.end[j];
|
||||
i++)
|
||||
{
|
||||
if (i == copy_kinetics.n_user[j])
|
||||
continue;
|
||||
Utilities::Rxn_copy(Rxn_kinetics_map, copy_kinetics.n_user[j], i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (verbose == TRUE)
|
||||
{
|
||||
warning_msg("KINETICS to copy not found.");
|
||||
return_value = ERROR;
|
||||
}
|
||||
if (i == copy_gas_phase.n_user[j])
|
||||
continue;
|
||||
Utilities::Rxn_copy(Rxn_gas_phase_map, copy_gas_phase.n_user[j], (int)i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (copy_ss_assemblage.count > 0)
|
||||
copier_clear(©_gas_phase);
|
||||
|
||||
for (size_t j = 0; j < copy_kinetics.n_user.size(); j++)
|
||||
{
|
||||
for (j = 0; j < copy_ss_assemblage.count; j++)
|
||||
if (Utilities::Rxn_find(Rxn_kinetics_map, copy_kinetics.n_user[j]) != NULL)
|
||||
{
|
||||
if (Utilities::Rxn_find(Rxn_ss_assemblage_map, copy_ss_assemblage.n_user[j]) != NULL)
|
||||
for (size_t i = copy_kinetics.start[j]; i <= copy_kinetics.end[j]; i++)
|
||||
{
|
||||
for (i = copy_ss_assemblage.start[j];
|
||||
i <= copy_ss_assemblage.end[j]; i++)
|
||||
{
|
||||
if (i == copy_ss_assemblage.n_user[j])
|
||||
continue;
|
||||
Utilities::Rxn_copy(Rxn_ss_assemblage_map, copy_ss_assemblage.n_user[j], i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (verbose == TRUE)
|
||||
{
|
||||
warning_msg("SOLID_SOLUTIONS to copy not found.");
|
||||
return_value = ERROR;
|
||||
}
|
||||
if (i == copy_kinetics.n_user[j])
|
||||
continue;
|
||||
Utilities::Rxn_copy(Rxn_kinetics_map, copy_kinetics.n_user[j], (int)i);
|
||||
}
|
||||
}
|
||||
}
|
||||
copy_solution.count = 0;
|
||||
copy_pp_assemblage.count = 0;
|
||||
copy_exchange.count = 0;
|
||||
copy_surface.count = 0;
|
||||
copy_ss_assemblage.count = 0;
|
||||
copy_gas_phase.count = 0;
|
||||
copy_kinetics.count = 0;
|
||||
copy_mix.count = 0;
|
||||
copy_reaction.count = 0;
|
||||
copy_temperature.count = 0;
|
||||
copy_pressure.count = 0;
|
||||
copier_clear(©_kinetics);
|
||||
|
||||
for (size_t j = 0; j < copy_ss_assemblage.n_user.size(); j++)
|
||||
{
|
||||
if (Utilities::Rxn_find(Rxn_ss_assemblage_map, copy_ss_assemblage.n_user[j]) != NULL)
|
||||
{
|
||||
for (size_t i = copy_ss_assemblage.start[j]; i <= copy_ss_assemblage.end[j]; i++)
|
||||
{
|
||||
if (i == copy_ss_assemblage.n_user[j])
|
||||
continue;
|
||||
Utilities::Rxn_copy(Rxn_ss_assemblage_map, copy_ss_assemblage.n_user[j], (int)i);
|
||||
}
|
||||
}
|
||||
}
|
||||
copier_clear(©_ss_assemblage);
|
||||
|
||||
new_copy = FALSE;
|
||||
return return_value;
|
||||
}
|
||||
@ -2260,12 +2087,14 @@ run_simulations(void)
|
||||
if (read_input() == EOF)
|
||||
break;
|
||||
|
||||
if (title_x != NULL)
|
||||
if (title_x.size() > 0)
|
||||
{
|
||||
sprintf(token, "TITLE");
|
||||
dup_print(token, TRUE);
|
||||
if (pr.headings == TRUE)
|
||||
output_msg(sformatf( "%s\n\n", title_x));
|
||||
{
|
||||
output_msg(sformatf("%s\n\n", title_x.c_str()));
|
||||
}
|
||||
}
|
||||
tidy_model();
|
||||
/*
|
||||
@ -2388,9 +2217,12 @@ do_status(void)
|
||||
screen_msg("\n");
|
||||
}
|
||||
//pr.headings = TRUE; // set in class_main; not set for IPhreeqc
|
||||
LDBLE ext = (double) clock() / CLOCKS_PER_SEC;
|
||||
#define TESTING
|
||||
#ifndef TESTING
|
||||
LDBLE ext = (double)clock() / CLOCKS_PER_SEC;
|
||||
dup_print(sformatf("End of Run after %g Seconds.", ext), TRUE);
|
||||
screen_msg(sformatf("\nEnd of Run after %g Seconds.\n", ext));
|
||||
#endif
|
||||
// appt this gives output when the charts are active...
|
||||
phrq_io->output_flush();
|
||||
phrq_io->error_flush();
|
||||
|
||||
@ -53,7 +53,7 @@ model(void)
|
||||
input_error++;
|
||||
error_msg("Cannot use PITZER and SIT data blocks in same run (database + input file).", STOP);
|
||||
}
|
||||
if ((pitzer_model == TRUE || sit_model == TRUE) && llnl_count_temp >0)
|
||||
if ((pitzer_model == TRUE || sit_model == TRUE) && llnl_temp.size() > 0)
|
||||
{
|
||||
input_error++;
|
||||
error_msg("Cannot use LLNL_AQUEOUS_MODEL_PARAMETERS with PITZER or SIT data blocks in same run (database + input file).", STOP);
|
||||
@ -570,17 +570,17 @@ gammas(LDBLE mu)
|
||||
/*
|
||||
* LLNL temperature dependence
|
||||
*/
|
||||
if (llnl_count_temp > 0)
|
||||
if (llnl_temp.size() > 0)
|
||||
{
|
||||
ifirst = 0;
|
||||
ilast = llnl_count_temp;
|
||||
if (tc_x < llnl_temp[0] || tc_x > llnl_temp[llnl_count_temp - 1])
|
||||
ilast = (int)llnl_temp.size();
|
||||
if (tc_x < llnl_temp[0] || tc_x > llnl_temp[llnl_temp.size() - 1])
|
||||
{
|
||||
error_msg
|
||||
("Temperature out of range of LLNL_AQUEOUS_MODEL parameters",
|
||||
STOP);
|
||||
}
|
||||
for (i = 0; i < llnl_count_temp; i++)
|
||||
for (i = 0; i < (int)llnl_temp.size(); i++)
|
||||
{
|
||||
if (tc_x >= llnl_temp[i])
|
||||
ifirst = i;
|
||||
@ -629,7 +629,7 @@ gammas(LDBLE mu)
|
||||
(2 * muhalf * (muhalf + 1.0) * (muhalf + 1.0)) -
|
||||
0.3);
|
||||
c2 = -a / (2 * muhalf);
|
||||
if (llnl_count_temp > 0)
|
||||
if (llnl_temp.size() > 0)
|
||||
{
|
||||
c2_llnl = -a_llnl / (2 * muhalf);
|
||||
}
|
||||
@ -674,18 +674,18 @@ gammas(LDBLE mu)
|
||||
continue;
|
||||
{
|
||||
LDBLE coef = 0, z = 0;
|
||||
for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++)
|
||||
for (j = 1; s_x[i]->rxn_x.token[j].s != NULL; j++)
|
||||
{
|
||||
if (s_x[i]->rxn_x->token[j].s->type == EX)
|
||||
if (s_x[i]->rxn_x.token[j].s->type == EX)
|
||||
{
|
||||
s_x[i]->alk =
|
||||
s_x[i]->rxn_x->token[j].s->primary->unknown->moles;
|
||||
s_x[i]->rxn_x.token[j].s->primary->unknown->moles;
|
||||
//break;
|
||||
}
|
||||
else if (s_x[i]->rxn_x->token[j].s->type <= HPLUS)
|
||||
else if (s_x[i]->rxn_x.token[j].s->type <= HPLUS)
|
||||
{
|
||||
coef = s_x[i]->rxn_x->token[j].coef;
|
||||
z = s_x[i]->rxn_x->token[j].s->z;
|
||||
coef = s_x[i]->rxn_x.token[j].coef;
|
||||
z = s_x[i]->rxn_x.token[j].s->z;
|
||||
}
|
||||
}
|
||||
if (!use.Get_exchange_ptr()->Get_pitzer_exchange_gammas())
|
||||
@ -725,7 +725,7 @@ gammas(LDBLE mu)
|
||||
}
|
||||
else if (s_x[i]->exch_gflag == 7 && s_x[i]->alk > 0)
|
||||
{
|
||||
if (llnl_count_temp > 0)
|
||||
if (llnl_temp.size() > 0)
|
||||
{
|
||||
s_x[i]->lg =
|
||||
coef * (-a_llnl * muhalf * z * z /
|
||||
@ -775,12 +775,12 @@ gammas(LDBLE mu)
|
||||
* Find moles of sites.
|
||||
* s_x[i]->equiv is stoichiometric coefficient of sites in species
|
||||
*/
|
||||
for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++)
|
||||
for (j = 1; s_x[i]->rxn_x.token[j].s != NULL; j++)
|
||||
{
|
||||
if (s_x[i]->rxn_x->token[j].s->type == SURF)
|
||||
if (s_x[i]->rxn_x.token[j].s->type == SURF)
|
||||
{
|
||||
s_x[i]->alk =
|
||||
s_x[i]->rxn_x->token[j].s->primary->unknown->moles;
|
||||
s_x[i]->rxn_x.token[j].s->primary->unknown->moles;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -805,7 +805,7 @@ gammas(LDBLE mu)
|
||||
}
|
||||
break;
|
||||
case 7: /* LLNL */
|
||||
if (llnl_count_temp > 0)
|
||||
if (llnl_temp.size() > 0)
|
||||
{
|
||||
if (s_x[i]->z == 0)
|
||||
{
|
||||
@ -834,7 +834,7 @@ gammas(LDBLE mu)
|
||||
}
|
||||
break;
|
||||
case 8: /* LLNL CO2 */
|
||||
if (llnl_count_temp > 0)
|
||||
if (llnl_temp.size() > 0)
|
||||
{
|
||||
s_x[i]->lg = log_g_co2;
|
||||
s_x[i]->dg = dln_g_co2 * s_x[i]->moles;
|
||||
@ -872,13 +872,13 @@ int Phreeqc::gammas_a_f(int i1)
|
||||
//struct master *m_ptr;
|
||||
|
||||
i = i1;
|
||||
for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++)
|
||||
for (j = 1; s_x[i]->rxn_x.token[j].s != NULL; j++)
|
||||
{
|
||||
if (s_x[i]->rxn_x->token[j].s->type == EX)
|
||||
if (s_x[i]->rxn_x.token[j].s->type == EX)
|
||||
{
|
||||
//strcpy(name, s_x[i]->rxn_x->token[j].s->name);
|
||||
name = s_x[i]->rxn_x->token[j].s->name;
|
||||
//m_ptr = s_x[i]->rxn_x->token[j].s->primary->elt->master; // appt debug
|
||||
//strcpy(name, s_x[i]->rxn_x.token[j].s->name);
|
||||
name = s_x[i]->rxn_x.token[j].s->name;
|
||||
//m_ptr = s_x[i]->rxn_x.token[j].s->primary->elt->master; // appt debug
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -887,11 +887,11 @@ int Phreeqc::gammas_a_f(int i1)
|
||||
{
|
||||
if (s_x[i]->gflag != 4 || s_x[i]->primary)
|
||||
continue;
|
||||
for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++)
|
||||
for (j = 1; s_x[i]->rxn_x.token[j].s != NULL; j++)
|
||||
{
|
||||
if (s_x[i]->rxn_x->token[j].s->type == EX)
|
||||
if (s_x[i]->rxn_x.token[j].s->type == EX)
|
||||
{
|
||||
if (!strcmp(name.c_str(), s_x[i]->rxn_x->token[j].s->name))
|
||||
if (!strcmp(name.c_str(), s_x[i]->rxn_x.token[j].s->name))
|
||||
sum += s_x[i]->moles * s_x[i]->equiv;
|
||||
break;
|
||||
}
|
||||
@ -1008,11 +1008,11 @@ ineq(int in_kode)
|
||||
{
|
||||
for (j = 0; j < count_unknowns; j++)
|
||||
{
|
||||
my_array[(size_t)j * ((size_t)count_unknowns + 1) + i] = 0.0;
|
||||
my_array[(size_t)j * (count_unknowns + 1) + i] = 0.0;
|
||||
}
|
||||
for (j = 0; j < count_unknowns + 1; j++)
|
||||
{
|
||||
my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)j] = 0.0;
|
||||
my_array[(size_t)i * (count_unknowns + 1) + (size_t)j] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1020,7 +1020,7 @@ ineq(int in_kode)
|
||||
/*
|
||||
* Normalize column
|
||||
*/
|
||||
normal.resize((size_t)count_unknowns);
|
||||
normal.resize(count_unknowns);
|
||||
std::fill(normal.begin(), normal.end(), 1.0);
|
||||
|
||||
for (i = 0; i < count_unknowns; i++)
|
||||
@ -1041,24 +1041,24 @@ ineq(int in_kode)
|
||||
if (x[i]->type == SURFACE_CB1 && x[j]->type == SURFACE_CB2)
|
||||
continue;
|
||||
|
||||
if (fabs(my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i]) > max)
|
||||
if (fabs(my_array[(size_t)j * (count_unknowns + 1) + (size_t)i]) > max)
|
||||
{
|
||||
max = fabs(my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i]);
|
||||
max = fabs(my_array[(size_t)j * (count_unknowns + 1) + (size_t)i]);
|
||||
if (max > min_value)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (diagonal_scale == TRUE)
|
||||
{
|
||||
if (fabs(my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i]) < min_value)
|
||||
if (fabs(my_array[(size_t)i * (count_unknowns + 1) + (size_t)i]) < min_value)
|
||||
{
|
||||
max = fabs(my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i]);
|
||||
max = fabs(my_array[(size_t)i * (count_unknowns + 1) + (size_t)i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (max == 0)
|
||||
{
|
||||
my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i] = 1e-5 * x[i]->moles;
|
||||
my_array[(size_t)i * (count_unknowns + 1) + (size_t)i] = 1e-5 * x[i]->moles;
|
||||
max = fabs(1e-5 * x[i]->moles);
|
||||
}
|
||||
}
|
||||
@ -1069,9 +1069,9 @@ ineq(int in_kode)
|
||||
|
||||
min = 1e-12;
|
||||
min = MIN_TOTAL;
|
||||
my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) + (size_t)x[i]->number] += min;
|
||||
if (fabs(my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) + (size_t)x[i]->number]) < min)
|
||||
my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) + (size_t)x[i]->number] = min;
|
||||
my_array[(size_t)x[i]->number * (count_unknowns + 1) + (size_t)x[i]->number] += min;
|
||||
if (fabs(my_array[(size_t)x[i]->number * (count_unknowns + 1) + (size_t)x[i]->number]) < min)
|
||||
my_array[(size_t)x[i]->number * (count_unknowns + 1) + (size_t)x[i]->number] = min;
|
||||
max = 0.0;
|
||||
|
||||
for (j = 0; j < count_unknowns; j++)
|
||||
@ -1084,9 +1084,9 @@ ineq(int in_kode)
|
||||
x[j]->type != EXCH && x[j]->type != MH
|
||||
&& x[j]->type != MH2O)
|
||||
continue;
|
||||
if (fabs(my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i]) > max)
|
||||
if (fabs(my_array[(size_t)j * (count_unknowns + 1) + (size_t)i]) > max)
|
||||
{
|
||||
max = fabs(my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i]);
|
||||
max = fabs(my_array[(size_t)j * (count_unknowns + 1) + (size_t)i]);
|
||||
if (max > min_value)
|
||||
break;
|
||||
}
|
||||
@ -1103,7 +1103,7 @@ ineq(int in_kode)
|
||||
}
|
||||
for (j = 0; j < count_unknowns; j++)
|
||||
{
|
||||
my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] *= min_value / max;
|
||||
my_array[(size_t)j * (count_unknowns + 1) + (size_t)i] *= min_value / max;
|
||||
}
|
||||
normal[i] = min_value / max;
|
||||
}
|
||||
@ -1114,14 +1114,14 @@ ineq(int in_kode)
|
||||
*/
|
||||
max_row_count = 2 * count_unknowns + 2;
|
||||
max_column_count = count_unknowns + 2;
|
||||
ineq_array.resize((size_t)max_row_count * (size_t)max_column_count);
|
||||
back_eq.resize((size_t)max_row_count);
|
||||
zero.resize((size_t)max_row_count);
|
||||
memset(&zero[0], 0, (size_t)max_row_count * sizeof(double));
|
||||
res.resize((size_t)max_row_count);
|
||||
memset(&res[0], 0, (size_t)max_row_count * sizeof(double));
|
||||
delta1.resize((size_t)max_column_count);
|
||||
memset(&delta1[0], 0,(size_t)max_column_count * sizeof(double));
|
||||
ineq_array.resize(max_row_count * max_column_count);
|
||||
back_eq.resize(max_row_count);
|
||||
zero.resize(max_row_count);
|
||||
memset(&zero[0], 0, max_row_count * sizeof(double));
|
||||
res.resize(max_row_count);
|
||||
memset(&res[0], 0, max_row_count * sizeof(double));
|
||||
delta1.resize(max_column_count);
|
||||
memset(&delta1[0], 0,max_column_count * sizeof(double));
|
||||
/*
|
||||
* Copy equations to optimize into ineq_array
|
||||
*/
|
||||
@ -1166,9 +1166,9 @@ ineq(int in_kode)
|
||||
else
|
||||
{
|
||||
/* Copy in saturation index equation (has mass or supersaturated) */
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]),
|
||||
((size_t)count_unknowns + 1) * sizeof(LDBLE));
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * (count_unknowns + 1)]),
|
||||
(count_unknowns + 1) * sizeof(LDBLE));
|
||||
back_eq[l_count_rows] = i;
|
||||
//if (it->second.Get_add_formula().size() == 0
|
||||
if (comp_ptr->Get_add_formula().size() == 0
|
||||
@ -1183,7 +1183,7 @@ ineq(int in_kode)
|
||||
{
|
||||
for (j = 0; j < count_unknowns + 1; j++)
|
||||
{
|
||||
ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)j] *= pp_scale;
|
||||
ineq_array[(size_t)l_count_rows * max_column_count + (size_t)j] *= pp_scale;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1199,9 +1199,9 @@ ineq(int in_kode)
|
||||
/*
|
||||
* Alkalinity and solution phase boundary
|
||||
*/
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]),
|
||||
((size_t)count_unknowns + 1) * sizeof(LDBLE));
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * (count_unknowns + 1)]),
|
||||
(count_unknowns + 1) * sizeof(LDBLE));
|
||||
back_eq[l_count_rows] = i;
|
||||
l_count_rows++;
|
||||
/*
|
||||
@ -1210,9 +1210,9 @@ ineq(int in_kode)
|
||||
}
|
||||
else if (x[i]->type == GAS_MOLES && gas_in == TRUE)
|
||||
{
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]),
|
||||
((size_t)count_unknowns + 1) * sizeof(LDBLE));
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * (count_unknowns + 1)]),
|
||||
(count_unknowns + 1) * sizeof(LDBLE));
|
||||
back_eq[l_count_rows] = i;
|
||||
|
||||
res[l_count_rows] = 1.0;
|
||||
@ -1227,9 +1227,9 @@ ineq(int in_kode)
|
||||
}
|
||||
else if (x[i]->type == SS_MOLES && x[i]->ss_in == TRUE)
|
||||
{
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]),
|
||||
((size_t)count_unknowns + 1) * sizeof(LDBLE));
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * (count_unknowns + 1)]),
|
||||
(count_unknowns + 1) * sizeof(LDBLE));
|
||||
back_eq[l_count_rows] = i;
|
||||
res[l_count_rows] = 1.0;
|
||||
if (in_kode != 1)
|
||||
@ -1309,26 +1309,26 @@ ineq(int in_kode)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]),
|
||||
((size_t)count_unknowns + 1) * sizeof(LDBLE));
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * (count_unknowns + 1)]),
|
||||
(count_unknowns + 1) * sizeof(LDBLE));
|
||||
back_eq[l_count_rows] = i;
|
||||
if (mass_water_switch == TRUE && x[i] == mass_hydrogen_unknown)
|
||||
{
|
||||
k = mass_oxygen_unknown->number;
|
||||
k = (int)mass_oxygen_unknown->number;
|
||||
for (j = 0; j < count_unknowns; j++)
|
||||
{
|
||||
ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)j] -=
|
||||
2 * my_array[(size_t)k * ((size_t)count_unknowns + 1) + (size_t)j];
|
||||
ineq_array[(size_t)l_count_rows * max_column_count + (size_t)j] -=
|
||||
2 * my_array[(size_t)k * (count_unknowns + 1) + (size_t)j];
|
||||
}
|
||||
}
|
||||
l_count_rows++;
|
||||
}
|
||||
else if (x[i]->type == PITZER_GAMMA && full_pitzer == TRUE)
|
||||
{
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]),
|
||||
((size_t)count_unknowns + 1) * sizeof(LDBLE));
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * (count_unknowns + 1)]),
|
||||
(count_unknowns + 1) * sizeof(LDBLE));
|
||||
back_eq[l_count_rows] = i;
|
||||
l_count_rows++;
|
||||
}
|
||||
@ -1369,13 +1369,9 @@ ineq(int in_kode)
|
||||
{
|
||||
|
||||
/* Pure phase is present, force Mass transfer to be <= amount of mineral remaining */
|
||||
//memcpy((void *)
|
||||
// &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]),
|
||||
// (void *) &(zero[0]),
|
||||
// ((size_t) count_unknowns + 1) * sizeof(LDBLE));
|
||||
memset(&ineq_array[(size_t)l_count_rows * (size_t)max_column_count], 0, ((size_t) count_unknowns + 1) * sizeof(LDBLE));
|
||||
ineq_array[(size_t)l_count_rows * (size_t)max_column_count + i] = 1.0;
|
||||
ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)count_unknowns] = x[i]->moles;
|
||||
memset(&ineq_array[(size_t)l_count_rows * max_column_count], 0, ((size_t) count_unknowns + 1) * sizeof(LDBLE));
|
||||
ineq_array[(size_t)l_count_rows * max_column_count + i] = 1.0;
|
||||
ineq_array[(size_t)l_count_rows * max_column_count + count_unknowns] = x[i]->moles;
|
||||
back_eq[l_count_rows] = i;
|
||||
l_count_rows++;
|
||||
}
|
||||
@ -1383,12 +1379,12 @@ ineq(int in_kode)
|
||||
if (x[i]->dissolve_only == TRUE)
|
||||
{
|
||||
//memcpy((void *)
|
||||
// &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]),
|
||||
// &(ineq_array[(size_t)l_count_rows * max_column_count]),
|
||||
// (void *) &(zero[0]),
|
||||
// ((size_t) count_unknowns + 1) * sizeof(LDBLE));
|
||||
memset(&(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), 0, ((size_t)count_unknowns + 1) * sizeof(LDBLE));
|
||||
ineq_array[(size_t)l_count_rows * (size_t)max_column_count + i] = -1.0;
|
||||
ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)count_unknowns] =
|
||||
memset(&(ineq_array[(size_t)l_count_rows * max_column_count]), 0, (count_unknowns + 1) * sizeof(LDBLE));
|
||||
ineq_array[(size_t)l_count_rows * max_column_count + i] = -1.0;
|
||||
ineq_array[(size_t)l_count_rows * max_column_count + count_unknowns] =
|
||||
comp_ptr->Get_initial_moles() - x[i]->moles;
|
||||
back_eq[l_count_rows] = i;
|
||||
l_count_rows++;
|
||||
@ -1405,22 +1401,22 @@ ineq(int in_kode)
|
||||
{
|
||||
if (x[i]->type == MH2O)
|
||||
{
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]),
|
||||
((size_t)count_unknowns + 1) * sizeof(LDBLE));
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * (count_unknowns + 1)]),
|
||||
(count_unknowns + 1) * sizeof(LDBLE));
|
||||
back_eq[l_count_rows] = i;
|
||||
for (j = 0; j < count_unknowns; j++)
|
||||
{
|
||||
if (x[j]->type < PP)
|
||||
{
|
||||
ineq_array[(size_t)l_count_rows * (size_t)max_column_count + j] = 0.0;
|
||||
ineq_array[(size_t)l_count_rows * max_column_count + j] = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/*ineq_array[l_count_rows*max_column_count + j] = -ineq_array[l_count_rows*max_column_count + j]; */
|
||||
}
|
||||
}
|
||||
ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)count_unknowns] =
|
||||
ineq_array[(size_t)l_count_rows * max_column_count + count_unknowns] =
|
||||
0.5 * x[i]->moles;
|
||||
l_count_rows++;
|
||||
}
|
||||
@ -1448,7 +1444,7 @@ ineq(int in_kode)
|
||||
{
|
||||
for (j = 0; j < l_count_rows; j++)
|
||||
{
|
||||
ineq_array[(size_t)j * (size_t)max_column_count + i] = 0.0;
|
||||
ineq_array[(size_t)j * max_column_count + i] = 0.0;
|
||||
}
|
||||
}
|
||||
if (x[i]->dissolve_only == TRUE)
|
||||
@ -1459,7 +1455,7 @@ ineq(int in_kode)
|
||||
{
|
||||
for (j = 0; j < l_count_rows; j++)
|
||||
{
|
||||
ineq_array[(size_t)j * (size_t)max_column_count + (size_t)i] = 0.0;
|
||||
ineq_array[(size_t)j * max_column_count + (size_t)i] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1479,7 +1475,7 @@ ineq(int in_kode)
|
||||
{
|
||||
for (j = 0; j < l_count_rows; j++)
|
||||
{
|
||||
ineq_array[(size_t)j * (size_t)max_column_count + i] = 0.0;
|
||||
ineq_array[(size_t)j * max_column_count + i] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1524,7 +1520,7 @@ ineq(int in_kode)
|
||||
{
|
||||
for (j = 0; j < l_count_rows; j++)
|
||||
{
|
||||
ineq_array[(size_t)j * (size_t)max_column_count + (size_t)i] = 0.0;
|
||||
ineq_array[(size_t)j * max_column_count + (size_t)i] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1553,7 +1549,7 @@ ineq(int in_kode)
|
||||
{
|
||||
for (j = 0; j < l_count_rows; j++)
|
||||
{
|
||||
ineq_array[(size_t)j * (size_t)max_column_count + (size_t)i] = 0.0;
|
||||
ineq_array[(size_t)j * max_column_count + (size_t)i] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1563,20 +1559,20 @@ ineq(int in_kode)
|
||||
*/
|
||||
if (gas_in == TRUE)
|
||||
{
|
||||
for (i = gas_unknown->number; i < count_unknowns; i++)
|
||||
for (i = (int)gas_unknown->number; i < (int)count_unknowns; i++)
|
||||
{
|
||||
if (x[i]->type == GAS_MOLES)
|
||||
{
|
||||
//memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]),
|
||||
//memcpy((void *) &(ineq_array[(size_t)l_count_rows * max_column_count]),
|
||||
// (void *) &(zero[0]),
|
||||
// ((size_t) count_unknowns + 1) * sizeof(LDBLE));
|
||||
//std::fill(&(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]),
|
||||
//std::fill(&(ineq_array[(size_t)l_count_rows * max_column_count]),
|
||||
// &(ineq_array[l_count_rows * max_column_count + count_unknowns]),
|
||||
// 0.0e0);
|
||||
memset(&(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), 0,
|
||||
((size_t)count_unknowns + 1) * sizeof(LDBLE));
|
||||
ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)i] = -1.0;
|
||||
ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)count_unknowns] =
|
||||
memset(&(ineq_array[(size_t)l_count_rows * max_column_count]), 0,
|
||||
(count_unknowns + 1) * sizeof(LDBLE));
|
||||
ineq_array[(size_t)l_count_rows * max_column_count + (size_t)i] = -1.0;
|
||||
ineq_array[(size_t)l_count_rows * max_column_count + count_unknowns] =
|
||||
x[i]->moles;
|
||||
back_eq[l_count_rows] = i;
|
||||
l_count_rows++;
|
||||
@ -1592,10 +1588,10 @@ ineq(int in_kode)
|
||||
/*
|
||||
* Moles of gas small and sum p < ptotal
|
||||
*/
|
||||
i = gas_unknown->number;
|
||||
i = (int)gas_unknown->number;
|
||||
for (j = 0; j < l_count_rows; j++)
|
||||
{
|
||||
ineq_array[(size_t)j * (size_t)max_column_count + (size_t)i] = 0.0;
|
||||
ineq_array[(size_t)j * max_column_count + (size_t)i] = 0.0;
|
||||
}
|
||||
}
|
||||
/*
|
||||
@ -1604,19 +1600,19 @@ ineq(int in_kode)
|
||||
|
||||
if (ss_unknown != NULL)
|
||||
{
|
||||
for (i = ss_unknown->number; i < count_unknowns; i++)
|
||||
for (i = (int)ss_unknown->number; i < (int)count_unknowns; i++)
|
||||
{
|
||||
if (x[i]->type != SS_MOLES)
|
||||
break;
|
||||
if (x[i]->phase->in == TRUE && x[i]->ss_in == TRUE)
|
||||
{
|
||||
//memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]),
|
||||
//memcpy((void *) &(ineq_array[(size_t)l_count_rows * max_column_count]),
|
||||
// (void *) &(zero[0]),
|
||||
// ((size_t) count_unknowns + 1) * sizeof(LDBLE));
|
||||
memset(&(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), 0,
|
||||
((size_t)count_unknowns + 1) * sizeof(LDBLE));
|
||||
ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)i] = 1.0;
|
||||
ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)count_unknowns] =
|
||||
memset(&(ineq_array[(size_t)l_count_rows * max_column_count]), 0,
|
||||
(count_unknowns + 1) * sizeof(LDBLE));
|
||||
ineq_array[(size_t)l_count_rows * max_column_count + (size_t)i] = 1.0;
|
||||
ineq_array[(size_t)l_count_rows * max_column_count + count_unknowns] =
|
||||
0.99 * x[i]->moles - MIN_TOTAL_SS;
|
||||
back_eq[l_count_rows] = i;
|
||||
l_count_rows++;
|
||||
@ -1625,7 +1621,7 @@ ineq(int in_kode)
|
||||
{
|
||||
for (j = 0; j < l_count_rows; j++)
|
||||
{
|
||||
ineq_array[(size_t)j * (size_t)max_column_count + (size_t)i] = 0.0;
|
||||
ineq_array[(size_t)j * max_column_count + (size_t)i] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1639,15 +1635,15 @@ ineq(int in_kode)
|
||||
{
|
||||
if (x[i]->type == MB && x[i]->moles < 0.0)
|
||||
{
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]),
|
||||
memcpy((void *) &(ineq_array[(size_t)l_count_rows * max_column_count]),
|
||||
(void *) &(my_array[(size_t)i * (count_unknowns + 1)]),
|
||||
((size_t) count_unknowns + 1) * sizeof(LDBLE));
|
||||
back_eq[l_count_rows] = i;
|
||||
for (j = 0; j < count_unknowns; j++)
|
||||
{
|
||||
if (x[j]->type < PP)
|
||||
{
|
||||
ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)j] = 0.0;
|
||||
ineq_array[(size_t)l_count_rows * max_column_count + (size_t)j] = 0.0;
|
||||
}
|
||||
}
|
||||
l_count_rows++;
|
||||
@ -1659,10 +1655,10 @@ ineq(int in_kode)
|
||||
*/
|
||||
if (mass_oxygen_unknown != NULL && mass_water_switch == TRUE)
|
||||
{
|
||||
k = mass_oxygen_unknown->number;
|
||||
k = (int)mass_oxygen_unknown->number;
|
||||
for (j = 0; j < l_count_rows + 1; j++)
|
||||
{
|
||||
ineq_array[(size_t)j * (size_t)max_column_count + (size_t)k] = 0;
|
||||
ineq_array[(size_t)j * max_column_count + (size_t)k] = 0;
|
||||
}
|
||||
}
|
||||
/*
|
||||
@ -1675,7 +1671,7 @@ ineq(int in_kode)
|
||||
{
|
||||
for (j = 0; j < l_count_rows; j++)
|
||||
{
|
||||
ineq_array[(size_t)j * (size_t)max_column_count + (size_t)i] *= pp_column_scale;
|
||||
ineq_array[(size_t)j * max_column_count + (size_t)i] *= pp_column_scale;
|
||||
}
|
||||
normal[i] = pp_column_scale;
|
||||
}
|
||||
@ -1684,8 +1680,8 @@ ineq(int in_kode)
|
||||
if (debug_model == TRUE)
|
||||
{
|
||||
output_msg(sformatf( "\nA and B arrays:\n\n"));
|
||||
array_print(&ineq_array[0], l_count_rows, count_unknowns + 1,
|
||||
max_column_count);
|
||||
array_print(&ineq_array[0], (int)l_count_rows, (int)count_unknowns + 1,
|
||||
(int)max_column_count);
|
||||
}
|
||||
/*
|
||||
* Calculate dimensions
|
||||
@ -1704,28 +1700,28 @@ ineq(int in_kode)
|
||||
#ifdef SHRINK_ARRAY
|
||||
if ((sit_model || pitzer_model) && full_pitzer == FALSE)
|
||||
{
|
||||
n = count_unknowns - (int) s_list.size();
|
||||
n = (int)count_unknowns - (int)s_list.size();
|
||||
for (int i = 0; i < l_count_rows; i++)
|
||||
{
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
ineq_array[(size_t)i*((size_t)n+2) + (size_t)j] = ineq_array[(size_t)i*((size_t)count_unknowns+2) + (size_t)j];
|
||||
ineq_array[(size_t)i*((size_t)n+2) + (size_t)j] = ineq_array[(size_t)i*(count_unknowns+2) + (size_t)j];
|
||||
}
|
||||
//if (i > 0)
|
||||
//{
|
||||
// memcpy((void *) &ineq_array[i*(n+2)], (void *) &ineq_array[i*(count_unknowns+2)], (size_t) (n) * sizeof(LDBLE));
|
||||
//}
|
||||
ineq_array[(size_t)i*((size_t)n+2) + (size_t)n] = ineq_array[(size_t)i*((size_t)count_unknowns+2) + (size_t)count_unknowns];
|
||||
ineq_array[(size_t)i*((size_t)n+2) + (size_t)n] = ineq_array[(size_t)i*(count_unknowns+2) + count_unknowns];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
n = count_unknowns; /* columns in A, C, E */
|
||||
n = (int)count_unknowns; /* columns in A, C, E */
|
||||
}
|
||||
#else
|
||||
n = count_unknowns; /* columns in A, C, E */
|
||||
#endif
|
||||
l_klmd = max_row_count - 2;
|
||||
l_klmd = (int)max_row_count - 2;
|
||||
l_nklmd = n + l_klmd;
|
||||
l_n2d = n + 2;
|
||||
/*
|
||||
@ -1840,7 +1836,7 @@ ineq(int in_kode)
|
||||
//memcpy((void *) &(delta[0]), (void *) &(zero[0]),
|
||||
// (size_t) count_unknowns * sizeof(LDBLE));
|
||||
memset(&(delta[0]), 0,
|
||||
(size_t)count_unknowns * sizeof(LDBLE));
|
||||
count_unknowns * sizeof(LDBLE));
|
||||
#endif
|
||||
memcpy((void *) &(delta[0]), (void *) &(delta1[0]),
|
||||
(size_t) n * sizeof(LDBLE));
|
||||
@ -1855,7 +1851,7 @@ ineq(int in_kode)
|
||||
{
|
||||
for (j = 0; j < count_unknowns; j++)
|
||||
{
|
||||
my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] /= normal[i];
|
||||
my_array[(size_t)j * (count_unknowns + 1) + (size_t)i] /= normal[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1936,7 +1932,7 @@ jacobian_sums(void)
|
||||
}
|
||||
for (i = 1; i < count_unknowns; i++)
|
||||
{
|
||||
memcpy((void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]),
|
||||
memcpy((void *) &(my_array[(size_t)i * (count_unknowns + 1)]),
|
||||
(void *) &(my_array[0]), (size_t) count_unknowns * sizeof(LDBLE));
|
||||
}
|
||||
/*
|
||||
@ -1971,9 +1967,9 @@ jacobian_sums(void)
|
||||
for (i = 0; i < count_unknowns; i++)
|
||||
{
|
||||
// using straight mu equation
|
||||
my_array[(size_t)mu_unknown->number * ((size_t)count_unknowns + 1) + i] *= 0.5;
|
||||
my_array[(size_t)mu_unknown->number * (count_unknowns + 1) + i] *= 0.5;
|
||||
}
|
||||
my_array[(size_t)mu_unknown->number * ((size_t)count_unknowns + 1) +
|
||||
my_array[(size_t)mu_unknown->number * (count_unknowns + 1) +
|
||||
(size_t)mu_unknown->number] -= mass_water_aq_x;
|
||||
}
|
||||
/*
|
||||
@ -1981,7 +1977,7 @@ jacobian_sums(void)
|
||||
*/
|
||||
if (mass_oxygen_unknown != NULL && mu_unknown != NULL)
|
||||
{
|
||||
my_array[(size_t)mu_unknown->number * ((size_t)count_unknowns + 1) +
|
||||
my_array[(size_t)mu_unknown->number * (count_unknowns + 1) +
|
||||
(size_t)mass_oxygen_unknown->number] -= mu_x * mass_water_aq_x;
|
||||
}
|
||||
/*
|
||||
@ -2001,16 +1997,16 @@ jacobian_sums(void)
|
||||
|
||||
for (i = 0; i < count_unknowns; i++)
|
||||
{
|
||||
my_array[(size_t)ah2o_unknown->number * ((size_t)count_unknowns + 1) + (size_t)i] *= factor;
|
||||
my_array[(size_t)ah2o_unknown->number * (count_unknowns + 1) + (size_t)i] *= factor;
|
||||
}
|
||||
// activity of water term
|
||||
my_array[(size_t)ah2o_unknown->number * ((size_t)count_unknowns + 1) +
|
||||
my_array[(size_t)ah2o_unknown->number * (count_unknowns + 1) +
|
||||
(size_t)ah2o_unknown->number] -= exp(s_h2o->la * LOG_10);
|
||||
|
||||
// mass of water term
|
||||
if (mass_oxygen_unknown != NULL)
|
||||
{
|
||||
my_array[(size_t)ah2o_unknown->number * ((size_t)count_unknowns + 1) + (size_t)mass_oxygen_unknown->number] -=
|
||||
my_array[(size_t)ah2o_unknown->number * (count_unknowns + 1) + (size_t)mass_oxygen_unknown->number] -=
|
||||
a*y_sum*(x_h2o*(0.5*tanh(lim) + 0.5) + (47.5*x_h2o - 50.0*a*y_sum)/(cosh(lim)*cosh(lim))) /
|
||||
(x_h2o*x_h2o*x_h2o);
|
||||
}
|
||||
@ -2019,13 +2015,13 @@ jacobian_sums(void)
|
||||
{
|
||||
for (i = 0; i < count_unknowns; i++)
|
||||
{
|
||||
my_array[(size_t)ah2o_unknown->number * ((size_t)count_unknowns + 1) + i] *= -AH2O_FACTOR;
|
||||
my_array[(size_t)ah2o_unknown->number * (count_unknowns + 1) + i] *= -AH2O_FACTOR;
|
||||
}
|
||||
my_array[(size_t)ah2o_unknown->number * ((size_t)count_unknowns + 1) + (size_t)ah2o_unknown->number] -=
|
||||
my_array[(size_t)ah2o_unknown->number * (count_unknowns + 1) + (size_t)ah2o_unknown->number] -=
|
||||
mass_water_aq_x * exp(s_h2o->la * LOG_10);
|
||||
if (mass_oxygen_unknown != NULL)
|
||||
{
|
||||
my_array[(size_t)ah2o_unknown->number * ((size_t)count_unknowns + 1) + (size_t)mass_oxygen_unknown->number] -=
|
||||
my_array[(size_t)ah2o_unknown->number * (count_unknowns + 1) + (size_t)mass_oxygen_unknown->number] -=
|
||||
(exp(s_h2o->la * LOG_10) - 1) * mass_water_aq_x;
|
||||
}
|
||||
}
|
||||
@ -2054,14 +2050,14 @@ jacobian_sums(void)
|
||||
{
|
||||
for (j = 0; j < count_unknowns; j++)
|
||||
{
|
||||
my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) + (size_t)j] *=
|
||||
my_array[(size_t)x[i]->number * (count_unknowns + 1) + (size_t)j] *=
|
||||
F_C_MOL / (charge_ptr->Get_specific_area() * charge_ptr->Get_grams());
|
||||
}
|
||||
my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) + (size_t)x[i]->number] -=
|
||||
my_array[(size_t)x[i]->number * (count_unknowns + 1) + (size_t)x[i]->number] -=
|
||||
sinh_constant * sqrt(mu_x) * cosh(x[i]->master[0]->s->la * LOG_10);
|
||||
if (mu_unknown != NULL)
|
||||
{
|
||||
my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) +
|
||||
my_array[(size_t)x[i]->number * (count_unknowns + 1) +
|
||||
(size_t)mu_unknown->number] -= 0.5 * sinh_constant / sqrt(mu_x) *
|
||||
sinh(x[i]->master[0]->s->la * LOG_10);
|
||||
}
|
||||
@ -2081,10 +2077,10 @@ jacobian_sums(void)
|
||||
{
|
||||
for (j = 0; j < count_unknowns; j++)
|
||||
{
|
||||
my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) + (size_t)j] *=
|
||||
my_array[(size_t)x[i]->number * (count_unknowns + 1) + (size_t)j] *=
|
||||
F_C_MOL / (charge_ptr->Get_specific_area() * charge_ptr->Get_grams());
|
||||
}
|
||||
my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) + (size_t)x[i]->number] -=
|
||||
my_array[(size_t)x[i]->number * (count_unknowns + 1) + (size_t)x[i]->number] -=
|
||||
charge_ptr->Get_capacitance0() * 2 * R_KJ_DEG_MOL * tk_x * LOG_10 / F_KJ_V_EQ;
|
||||
}
|
||||
}
|
||||
@ -2211,10 +2207,10 @@ mb_ss(void)
|
||||
/*
|
||||
* Calculate IAPc and IAPb
|
||||
*/
|
||||
if (phase0_ptr->in == TRUE && phase0_ptr->rxn_x != NULL)
|
||||
if (phase0_ptr->in == TRUE && phase0_ptr->rxn_x.token.size() != 0)
|
||||
{
|
||||
log10_iap = 0;
|
||||
for (rxn_ptr = phase0_ptr->rxn_x->token + 1;
|
||||
for (rxn_ptr = &phase0_ptr->rxn_x.token[0] + 1;
|
||||
rxn_ptr->s != NULL; rxn_ptr++)
|
||||
{
|
||||
log10_iap += rxn_ptr->s->la * rxn_ptr->coef;
|
||||
@ -2225,10 +2221,10 @@ mb_ss(void)
|
||||
{
|
||||
iapc = 1e-99;
|
||||
}
|
||||
if (phase1_ptr->in == TRUE && phase1_ptr->rxn_x != NULL)
|
||||
if (phase1_ptr->in == TRUE && phase1_ptr->rxn_x.token.size() != 0)
|
||||
{
|
||||
log10_iap = 0;
|
||||
for (rxn_ptr = phase1_ptr->rxn_x->token + 1;
|
||||
for (rxn_ptr = &phase1_ptr->rxn_x.token[0] + 1;
|
||||
rxn_ptr->s != NULL; rxn_ptr++)
|
||||
{
|
||||
log10_iap += rxn_ptr->s->la * rxn_ptr->coef;
|
||||
@ -2293,7 +2289,7 @@ mb_ss(void)
|
||||
if (phase_ptr->in == TRUE)
|
||||
{
|
||||
lp = -phase_ptr->lk;
|
||||
for (rxn_ptr = phase_ptr->rxn_x->token + 1;
|
||||
for (rxn_ptr = &phase_ptr->rxn_x.token[0] + 1;
|
||||
rxn_ptr->s != NULL; rxn_ptr++)
|
||||
{
|
||||
lp += rxn_ptr->s->la * rxn_ptr->coef;
|
||||
@ -2311,7 +2307,7 @@ mb_ss(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = ss_unknown->number; i < count_unknowns; i++)
|
||||
for (int i = (int)ss_unknown->number; i < (int)count_unknowns; i++)
|
||||
{
|
||||
if (x[i]->type != SS_MOLES)
|
||||
break;
|
||||
@ -2367,7 +2363,7 @@ molalities(int allow_overflow)
|
||||
* lm and moles for all aqueous species
|
||||
*/
|
||||
s_x[i]->lm = s_x[i]->lk - s_x[i]->lg;
|
||||
for (rxn_ptr = s_x[i]->rxn_x->token + 1; rxn_ptr->s != NULL;
|
||||
for (rxn_ptr = &s_x[i]->rxn_x.token[0] + 1; rxn_ptr->s != NULL;
|
||||
rxn_ptr++)
|
||||
{
|
||||
s_x[i]->lm += rxn_ptr->s->la * rxn_ptr->coef;
|
||||
@ -2639,7 +2635,7 @@ calc_gas_pressures(void)
|
||||
if (phase_ptr->in == TRUE)
|
||||
{
|
||||
lp = -phase_ptr->lk;
|
||||
for (rxn_ptr = phase_ptr->rxn_x->token + 1; rxn_ptr->s != NULL;
|
||||
for (rxn_ptr = &phase_ptr->rxn_x.token[0] + 1; rxn_ptr->s != NULL;
|
||||
rxn_ptr++)
|
||||
{
|
||||
lp += rxn_ptr->s->la * rxn_ptr->coef;
|
||||
@ -2690,7 +2686,7 @@ calc_gas_pressures(void)
|
||||
* Fixed-volume gas phase reacting with a solution
|
||||
* Change pressure used in logK to pressure of gas phase
|
||||
*/
|
||||
if (gas_phase_ptr->Get_total_p() > MAX_P_NONLLNL && llnl_count_temp <= 0)
|
||||
if (gas_phase_ptr->Get_total_p() > MAX_P_NONLLNL && llnl_temp.size() == 0)
|
||||
{
|
||||
gas_phase_ptr->Set_total_moles(0);
|
||||
for (size_t i = 0; i < gas_phase_ptr->Get_gas_comps().size(); i++)
|
||||
@ -3686,7 +3682,7 @@ reset(void)
|
||||
//{
|
||||
// patm_x = ( 1 * patm_x + p_sat) / 2.0;
|
||||
//}
|
||||
if (llnl_count_temp <= 0)
|
||||
if (llnl_temp.size() == 0)
|
||||
{
|
||||
if (patm_x > MAX_P_NONLLNL)
|
||||
patm_x = MAX_P_NONLLNL;
|
||||
@ -4235,7 +4231,7 @@ residuals(void)
|
||||
cd_psi.push_back(-(master_ptr2->s->la * LOG_10) * R_KJ_DEG_MOL * tk_x /
|
||||
F_KJ_V_EQ);
|
||||
sum = 0;
|
||||
for (j = 0; j < x[i]->count_comp_unknowns; j++)
|
||||
for (size_t j = 0; j < x[i]->comp_unknowns.size(); j++)
|
||||
{
|
||||
sum +=
|
||||
x[i]->comp_unknowns[j]->moles *
|
||||
@ -4526,7 +4522,7 @@ residuals(void)
|
||||
/*
|
||||
* Store residuals in array
|
||||
*/
|
||||
my_array[((size_t)i + 1) * ((size_t)count_unknowns + 1) - 1] = residual[i];
|
||||
my_array[((size_t)i + 1) * (count_unknowns + 1) - 1] = residual[i];
|
||||
sum_residual += fabs(residual[i]);
|
||||
}
|
||||
/*
|
||||
@ -4880,7 +4876,7 @@ sum_species(void)
|
||||
*
|
||||
* Sums total valence states and stores in master[i]->total.
|
||||
*/
|
||||
int i, j;
|
||||
int i;
|
||||
struct master *master_ptr;
|
||||
/*
|
||||
* Set global variables
|
||||
@ -4962,7 +4958,7 @@ sum_species(void)
|
||||
(x[i]->type == CB && x[i] != ph_unknown && x[i] != pe_unknown))
|
||||
{
|
||||
x[i]->sum = 0.0;
|
||||
for (j = 0; x[i]->master[j] != NULL; j++)
|
||||
for (size_t j = 0; j < x[i]->master.size(); j++)
|
||||
{
|
||||
x[i]->sum += x[i]->master[j]->total;
|
||||
}
|
||||
@ -5001,7 +4997,7 @@ surface_model(void)
|
||||
*/
|
||||
debug_diffuse_layer_save = debug_diffuse_layer;
|
||||
debug_model_save = debug_model;
|
||||
if (last_model.force_prep == TRUE)
|
||||
if (last_model.force_prep)
|
||||
{
|
||||
same_model = FALSE;
|
||||
}
|
||||
@ -5334,10 +5330,10 @@ numerical_jacobian(void)
|
||||
}
|
||||
for (i = 1; i < count_unknowns; i++)
|
||||
{
|
||||
memcpy((void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]),
|
||||
(void *) &(my_array[0]), (size_t)count_unknowns * sizeof(LDBLE));
|
||||
memcpy((void *) &(my_array[(size_t)i * (count_unknowns + 1)]),
|
||||
(void *) &(my_array[0]), count_unknowns * sizeof(LDBLE));
|
||||
}
|
||||
base.resize((size_t)count_unknowns);
|
||||
base.resize(count_unknowns);
|
||||
base = residual;
|
||||
d = 0.0001;
|
||||
d1 = d * LOG_10;
|
||||
@ -5444,13 +5440,13 @@ numerical_jacobian(void)
|
||||
LDBLE t = (LDBLE) pow((LDBLE) 10.0, (LDBLE) (DBL_MAX_10_EXP - 50.0));
|
||||
if (residual[j] > t)
|
||||
{
|
||||
my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] = -pow(10.0, DBL_MAX_10_EXP - 50.0);
|
||||
my_array[(size_t)j * (count_unknowns + 1) + (size_t)i] = -pow(10.0, DBL_MAX_10_EXP - 50.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] = -(residual[j] - base[j]) / d2;
|
||||
my_array[(size_t)j * (count_unknowns + 1) + (size_t)i] = -(residual[j] - base[j]) / d2;
|
||||
if (x[i]->type == MH2O) // DL_pitz
|
||||
my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] *= mass_water_aq_x;
|
||||
my_array[(size_t)j * (count_unknowns + 1) + (size_t)i] *= mass_water_aq_x;
|
||||
}
|
||||
}
|
||||
else if (residual[j] < -1.0e101)
|
||||
@ -5458,21 +5454,21 @@ numerical_jacobian(void)
|
||||
LDBLE t = pow((LDBLE) 10.0, (LDBLE) (DBL_MIN_10_EXP + 50.0));
|
||||
if (residual[j] < -t)
|
||||
{
|
||||
my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] = pow(10.0, DBL_MIN_10_EXP + 50.0);
|
||||
my_array[(size_t)j * (count_unknowns + 1) + (size_t)i] = pow(10.0, DBL_MIN_10_EXP + 50.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] = -(residual[j] - base[j]) / d2;
|
||||
my_array[(size_t)j * (count_unknowns + 1) + (size_t)i] = -(residual[j] - base[j]) / d2;
|
||||
if (x[i]->type == MH2O) // DL_pitz
|
||||
my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] *= mass_water_aq_x;
|
||||
my_array[(size_t)j * (count_unknowns + 1) + (size_t)i] *= mass_water_aq_x;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] = -(residual[j] - base[j]) / d2;
|
||||
my_array[(size_t)j * (count_unknowns + 1) + (size_t)i] = -(residual[j] - base[j]) / d2;
|
||||
if (x[i]->type == MH2O) // DL_pitz
|
||||
my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] *= mass_water_aq_x;
|
||||
if (!PHR_ISFINITE(my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i]))
|
||||
my_array[(size_t)j * (count_unknowns + 1) + (size_t)i] *= mass_water_aq_x;
|
||||
if (!PHR_ISFINITE(my_array[(size_t)j * (count_unknowns + 1) + (size_t)i]))
|
||||
{
|
||||
//fprintf(stderr, "oops, got NaN: %e, %e, %e, %e\n", residual[j], base[j], d2, array[j * (count_unknowns + 1) + i]);
|
||||
}
|
||||
@ -5496,10 +5492,10 @@ numerical_jacobian(void)
|
||||
break;
|
||||
case MH:
|
||||
s_eminus->la -= d;
|
||||
if (my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i] == 0)
|
||||
if (my_array[(size_t)i * (count_unknowns + 1) + (size_t)i] == 0)
|
||||
{
|
||||
/*output_msg(sformatf( "Zero diagonal for MH\n")); */
|
||||
my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i] =
|
||||
my_array[(size_t)i * (count_unknowns + 1) + (size_t)i] =
|
||||
under(s_h2->lm) * 2;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
#include "Phreeqc.h"
|
||||
#include "phqalloc.h"
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
parse_eq(char *eqn, struct elt_list **elt_ptr, int association)
|
||||
parse_eq(char* eqn, std::vector<struct elt_list>& new_elt_list, int association)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/*
|
||||
* function to break equation up into component species
|
||||
@ -26,69 +25,69 @@ parse_eq(char *eqn, struct elt_list **elt_ptr, int association)
|
||||
int i;
|
||||
LDBLE coef, l_z;
|
||||
char c;
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
char token[MAX_LENGTH];
|
||||
|
||||
paren_count = 0;
|
||||
/*
|
||||
* Remove white space
|
||||
*/
|
||||
/*
|
||||
* Remove white space
|
||||
*/
|
||||
squeeze_white(eqn);
|
||||
/*
|
||||
* Check for illegal characters
|
||||
*/
|
||||
/*
|
||||
* Check for illegal characters
|
||||
*/
|
||||
for (i = 0; (c = eqn[i]) != '\0'; i++)
|
||||
{
|
||||
if (islegit(c) == FALSE)
|
||||
{
|
||||
error_string = sformatf( "Character is not allowed,\
|
||||
error_string = sformatf("Character is not allowed,\
|
||||
%c (octal: %o).", c, c);
|
||||
error_msg(error_string, CONTINUE);
|
||||
return (ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Find coefficients, name, and charge for each species for lhs
|
||||
*/
|
||||
/*
|
||||
* Find coefficients, name, and charge for each species for lhs
|
||||
*/
|
||||
count_trxn = 0;
|
||||
trxn.dz[0] = trxn.dz[1] = trxn.dz[2] = 0.0;
|
||||
ptr = eqn;
|
||||
c = ptr[0];
|
||||
cptr = eqn;
|
||||
c = cptr[0];
|
||||
for (;;)
|
||||
{
|
||||
if (c == '=')
|
||||
break;
|
||||
if (c == '\0')
|
||||
{
|
||||
error_string = sformatf( "Equation has no equal sign.\n\t%s", eqn);
|
||||
error_string = sformatf("Equation has no equal sign.\n\t%s", eqn);
|
||||
error_msg(error_string, CONTINUE);
|
||||
return (ERROR);
|
||||
}
|
||||
if (get_species(&ptr) == ERROR)
|
||||
if (get_species(&cptr) == ERROR)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
c = ptr[0];
|
||||
c = cptr[0];
|
||||
if (association == FALSE)
|
||||
{
|
||||
trxn.token[count_trxn].coef *= -1.0;
|
||||
}
|
||||
count_trxn++;
|
||||
}
|
||||
/*
|
||||
* Get coefficient, name, and charge of species for dissociation reaction
|
||||
*/
|
||||
ptr++;
|
||||
/*
|
||||
* Get coefficient, name, and charge of species for dissociation reaction
|
||||
*/
|
||||
cptr++;
|
||||
if (association == TRUE)
|
||||
{
|
||||
if (get_species(&ptr) == ERROR)
|
||||
if (get_species(&cptr) == ERROR)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
trxn.token[count_trxn].coef *= -1.0;
|
||||
/* Swap species into first structure position */
|
||||
const char * char_ptr = trxn.token[0].name;
|
||||
const char* char_ptr = trxn.token[0].name;
|
||||
coef = trxn.token[0].coef;
|
||||
l_z = trxn.token[0].z;
|
||||
trxn.token[0].name = trxn.token[count_trxn].name;
|
||||
@ -99,74 +98,66 @@ parse_eq(char *eqn, struct elt_list **elt_ptr, int association)
|
||||
trxn.token[count_trxn].z = l_z;
|
||||
count_trxn++;
|
||||
}
|
||||
/*
|
||||
* Get reaction species from rhs of equation
|
||||
*/
|
||||
c = ptr[0];
|
||||
/*
|
||||
* Get reaction species from rhs of equation
|
||||
*/
|
||||
c = cptr[0];
|
||||
for (;;)
|
||||
{
|
||||
if (c == '\0')
|
||||
break;
|
||||
if (get_species(&ptr) == ERROR)
|
||||
if (get_species(&cptr) == ERROR)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
c = ptr[0];
|
||||
c = cptr[0];
|
||||
if (association == TRUE)
|
||||
{
|
||||
trxn.token[count_trxn].coef *= -1.0;
|
||||
}
|
||||
count_trxn++;
|
||||
}
|
||||
/*
|
||||
* Sort list of reaction species
|
||||
*/
|
||||
/*
|
||||
* Sort list of reaction species
|
||||
*/
|
||||
trxn_sort();
|
||||
/*
|
||||
* Get elements in species or mineral formula
|
||||
*/
|
||||
/*
|
||||
* Get elements in species or mineral formula
|
||||
*/
|
||||
count_elts = 0;
|
||||
strcpy(token, trxn.token[0].name);
|
||||
replace("(s)", "", token);
|
||||
replace("(S)", "", token);
|
||||
replace("(g)", "", token);
|
||||
replace("(G)", "", token);
|
||||
char *char_ptr = token;
|
||||
const char* char_ptr = token;
|
||||
|
||||
if (get_elts_in_species(&char_ptr, trxn.token[0].coef) == ERROR)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
/*
|
||||
* Sort elements in reaction and combine
|
||||
*/
|
||||
/*
|
||||
* Sort elements in reaction and combine
|
||||
*/
|
||||
if (elt_list_combine() == ERROR)
|
||||
return (ERROR);
|
||||
/*
|
||||
* Malloc space and store element data for return
|
||||
*/
|
||||
*elt_ptr = (struct elt_list *) PHRQ_malloc(((size_t)count_elts + 1) *
|
||||
sizeof(struct elt_list));
|
||||
if (*elt_ptr == NULL)
|
||||
/*
|
||||
* Malloc space and store element data for return
|
||||
*/
|
||||
new_elt_list.resize(count_elts + 1);
|
||||
for (i = 0; i < count_elts; i++)
|
||||
{
|
||||
malloc_error();
|
||||
new_elt_list[i].elt = elt_list[i].elt;
|
||||
new_elt_list[i].coef = -elt_list[i].coef;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < count_elts; i++)
|
||||
{
|
||||
(*elt_ptr)[i].elt = elt_list[i].elt;
|
||||
(*elt_ptr)[i].coef = -elt_list[i].coef;
|
||||
}
|
||||
(*elt_ptr)[count_elts].elt = NULL;
|
||||
}
|
||||
/*
|
||||
* Debugging print of parsed equation
|
||||
trxn_print();
|
||||
*/
|
||||
new_elt_list[count_elts].elt = NULL;
|
||||
|
||||
/*
|
||||
* Debugging print of parsed equation
|
||||
trxn_print();
|
||||
*/
|
||||
return (OK);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
check_eqn(int association)
|
||||
@ -213,14 +204,11 @@ check_eqn(int association)
|
||||
for (i = 0; i < count_trxn; i++)
|
||||
{
|
||||
sumcharge += (trxn.token[i].coef) * (trxn.token[i].z);
|
||||
char * temp_name = string_duplicate(trxn.token[i].name);
|
||||
char *t_ptr = temp_name;
|
||||
const char* t_ptr = trxn.token[i].name;
|
||||
if (get_elts_in_species(&t_ptr, trxn.token[i].coef) == ERROR)
|
||||
{
|
||||
free_check_null(temp_name);
|
||||
return (ERROR);
|
||||
}
|
||||
free_check_null(temp_name);
|
||||
}
|
||||
/*
|
||||
* Sort elements in reaction and combine
|
||||
@ -283,7 +271,7 @@ get_charge(char *charge, LDBLE * l_z)
|
||||
*/
|
||||
{
|
||||
int i;
|
||||
char *ptr;
|
||||
char* ptr;
|
||||
char c, c1;
|
||||
/*
|
||||
* Charge is zero
|
||||
@ -333,6 +321,7 @@ get_charge(char *charge, LDBLE * l_z)
|
||||
{
|
||||
if (*ptr != '0')
|
||||
{
|
||||
char* ptr;
|
||||
*l_z = strtod(charge, &ptr);
|
||||
return (OK);
|
||||
}
|
||||
@ -385,7 +374,7 @@ get_charge(char *charge, LDBLE * l_z)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
get_coef(LDBLE * coef, char **eqnaddr)
|
||||
get_coef(LDBLE * coef, const char **eqnaddr)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/*
|
||||
* Function reads through eqn and determines the coefficient of the next
|
||||
@ -404,12 +393,14 @@ get_coef(LDBLE * coef, char **eqnaddr)
|
||||
{
|
||||
int i;
|
||||
char c, c1;
|
||||
char *ptr, *ptr1, *rest;
|
||||
const char* cptr;
|
||||
const char* rest;
|
||||
char* ptr1;
|
||||
char token[MAX_LENGTH];;
|
||||
|
||||
rest = *eqnaddr;
|
||||
ptr = *eqnaddr; /* address of a position in eqn */
|
||||
c = *ptr; /* character in eqn */
|
||||
cptr = *eqnaddr; /* address of a position in eqn */
|
||||
c = *cptr; /* character in eqn */
|
||||
*coef = 0.0;
|
||||
/*
|
||||
* No leading sign or number
|
||||
@ -423,12 +414,12 @@ get_coef(LDBLE * coef, char **eqnaddr)
|
||||
/*
|
||||
* Leading +, no digits
|
||||
*/
|
||||
c1 = *(ptr + 1);
|
||||
c1 = *(cptr + 1);
|
||||
if (c == '+' &&
|
||||
(isalpha((int) c1) ||
|
||||
(c1 == '(') || (c1 == ')') || (c1 == '[') || (c1 == ']')))
|
||||
{
|
||||
*eqnaddr = ++ptr;
|
||||
*eqnaddr = ++cptr;
|
||||
*coef = 1.0;
|
||||
return (OK);
|
||||
}
|
||||
@ -439,7 +430,7 @@ get_coef(LDBLE * coef, char **eqnaddr)
|
||||
(isalpha((int) c1) ||
|
||||
(c1 == '(') || (c1 == ')') || (c1 == '[') || (c1 == ']')))
|
||||
{
|
||||
*eqnaddr = ++ptr;
|
||||
*eqnaddr = ++cptr;
|
||||
*coef = -1.0;
|
||||
return (OK);
|
||||
}
|
||||
@ -459,10 +450,10 @@ get_coef(LDBLE * coef, char **eqnaddr)
|
||||
error_msg(error_string, CONTINUE);
|
||||
return (ERROR);
|
||||
}
|
||||
c = *(++ptr);
|
||||
c = *(++cptr);
|
||||
}
|
||||
token[i] = '\0';
|
||||
*eqnaddr = ptr;
|
||||
*eqnaddr = cptr;
|
||||
errno = 0;
|
||||
*coef = strtod(token, &ptr1);
|
||||
if ((errno == ERANGE) || (*ptr1 != '\0'))
|
||||
@ -485,7 +476,7 @@ get_coef(LDBLE * coef, char **eqnaddr)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
get_elt(char **t_ptr, char *element, int *i)
|
||||
get_elt(const char** t_ptr, std::string& element, int* i)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/*
|
||||
* Function reads an element name out of the equation string.
|
||||
@ -501,29 +492,30 @@ get_elt(char **t_ptr, char *element, int *i)
|
||||
{
|
||||
char c;
|
||||
|
||||
element.clear();
|
||||
c = *(*t_ptr)++;
|
||||
if (c == '\0')
|
||||
{
|
||||
error_string = sformatf(
|
||||
"Empty string in get_elt. Expected an element name.");
|
||||
"Empty string in get_elt. Expected an element name.");
|
||||
error_msg(error_string, CONTINUE);
|
||||
return (ERROR);
|
||||
}
|
||||
/*
|
||||
* Load name into char array element
|
||||
*/
|
||||
element[0] = c;
|
||||
/*
|
||||
* Load name into char array element
|
||||
*/
|
||||
element.push_back(c);
|
||||
*i = 1;
|
||||
if (c == '[')
|
||||
{
|
||||
while ((c = (**t_ptr)) != ']')
|
||||
{
|
||||
element[*i] = c;
|
||||
element.push_back(c);
|
||||
(*i)++;
|
||||
(*t_ptr)++;
|
||||
if ((c = (**t_ptr)) == ']')
|
||||
{
|
||||
element[*i] = c;
|
||||
element.push_back(c);
|
||||
(*i)++;
|
||||
(*t_ptr)++;
|
||||
break;
|
||||
@ -535,29 +527,28 @@ get_elt(char **t_ptr, char *element, int *i)
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (islower((int) (c = (**t_ptr))) || c == '_')
|
||||
while (islower((int)(c = (**t_ptr))) || c == '_')
|
||||
{
|
||||
element[*i] = c;
|
||||
element.push_back(c);
|
||||
(*i)++;
|
||||
(*t_ptr)++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (islower((int) (c = (**t_ptr))) || c == '_')
|
||||
while (islower((int)(c = (**t_ptr))) || c == '_')
|
||||
{
|
||||
element[*i] = c;
|
||||
element.push_back(c);
|
||||
(*i)++;
|
||||
(*t_ptr)++;
|
||||
}
|
||||
}
|
||||
element[*i] = '\0';
|
||||
return (OK);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
get_elts_in_species(char **t_ptr, LDBLE coef)
|
||||
get_elts_in_species(const char **t_ptr, LDBLE coef)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -571,11 +562,12 @@ get_elts_in_species(char **t_ptr, LDBLE coef)
|
||||
* output, is next position to start looking
|
||||
* coef input, coefficient to multiply subscripts by
|
||||
*/
|
||||
int i, count, l;
|
||||
int l;
|
||||
size_t count;
|
||||
char c, c1;
|
||||
LDBLE d;
|
||||
char element[MAX_LENGTH];
|
||||
char** t_ptr_save = t_ptr;
|
||||
std::string element;
|
||||
const char** t_ptr_save = t_ptr;
|
||||
while (((c = **t_ptr) != '+') && (c != '-') && (c != '\0'))
|
||||
{
|
||||
/* close parenthesis */
|
||||
@ -604,9 +596,9 @@ get_elts_in_species(char **t_ptr, LDBLE coef)
|
||||
}
|
||||
if (count_elts >= (int)elt_list.size())
|
||||
{
|
||||
elt_list.resize((size_t)count_elts + 1);
|
||||
elt_list.resize(count_elts + 1);
|
||||
}
|
||||
elt_list[count_elts].elt = element_store(element);
|
||||
elt_list[count_elts].elt = element_store(element.c_str());
|
||||
if (get_num(t_ptr, &d) == ERROR)
|
||||
{
|
||||
return (ERROR);
|
||||
@ -618,7 +610,7 @@ get_elts_in_species(char **t_ptr, LDBLE coef)
|
||||
*/
|
||||
if (count_elts >= (int)elt_list.size())
|
||||
{
|
||||
elt_list.resize((size_t)count_elts + 1);
|
||||
elt_list.resize(count_elts + 1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -643,7 +635,7 @@ get_elts_in_species(char **t_ptr, LDBLE coef)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
for (i = count; i < count_elts; i++)
|
||||
for (size_t i = count; i < count_elts; i++)
|
||||
{
|
||||
elt_list[i].coef *= d;
|
||||
}
|
||||
@ -664,7 +656,7 @@ get_elts_in_species(char **t_ptr, LDBLE coef)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
for (i = count; i < count_elts; i++)
|
||||
for (size_t i = count; i < count_elts; i++)
|
||||
{
|
||||
elt_list[i].coef *= d;
|
||||
}
|
||||
@ -692,7 +684,7 @@ get_elts_in_species(char **t_ptr, LDBLE coef)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
get_secondary(char **t_ptr, char *element, int *i)
|
||||
get_secondary(const char **t_ptr, char *element, int *i)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/*
|
||||
* Function reads an element name out of the equation string.
|
||||
@ -708,7 +700,7 @@ get_secondary(char **t_ptr, char *element, int *i)
|
||||
{
|
||||
int j;
|
||||
char c;
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
|
||||
c = *(*t_ptr)++;
|
||||
if (c == '\0')
|
||||
@ -766,7 +758,7 @@ get_secondary(char **t_ptr, char *element, int *i)
|
||||
* Check if secondary master species element
|
||||
*/
|
||||
j = *i;
|
||||
ptr = *t_ptr;
|
||||
cptr = *t_ptr;
|
||||
if (c == '(')
|
||||
{
|
||||
/* copy parenthesis */
|
||||
@ -796,7 +788,7 @@ get_secondary(char **t_ptr, char *element, int *i)
|
||||
if (c != ')')
|
||||
{
|
||||
*i = j;
|
||||
*t_ptr = ptr;
|
||||
*t_ptr = cptr;
|
||||
/* put in closing parenthesis */
|
||||
}
|
||||
else
|
||||
@ -812,7 +804,7 @@ get_secondary(char **t_ptr, char *element, int *i)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
get_secondary_in_species(char **t_ptr, LDBLE coef)
|
||||
get_secondary_in_species(const char **t_ptr, LDBLE coef)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -826,11 +818,12 @@ get_secondary_in_species(char **t_ptr, LDBLE coef)
|
||||
* output, is next position to start looking
|
||||
* coef input, coefficient to multiply subscripts by
|
||||
*/
|
||||
int i, count, l;
|
||||
int l;
|
||||
size_t count;
|
||||
char c, c1;
|
||||
LDBLE d;
|
||||
char element[MAX_LENGTH];
|
||||
char** t_ptr_save = t_ptr;
|
||||
const char** t_ptr_save = t_ptr;
|
||||
while (((c = **t_ptr) != '+') && (c != '-') && (c != '\0'))
|
||||
{
|
||||
/* close parenthesis */
|
||||
@ -870,7 +863,7 @@ get_secondary_in_species(char **t_ptr, LDBLE coef)
|
||||
*/
|
||||
if (count_elts >= (int)elt_list.size())
|
||||
{
|
||||
elt_list.resize((size_t)count_elts + 1);
|
||||
elt_list.resize(count_elts + 1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -895,7 +888,7 @@ get_secondary_in_species(char **t_ptr, LDBLE coef)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
for (i = count; i < count_elts; i++)
|
||||
for (size_t i = count; i < count_elts; i++)
|
||||
{
|
||||
elt_list[i].coef *= d;
|
||||
}
|
||||
@ -916,7 +909,7 @@ get_secondary_in_species(char **t_ptr, LDBLE coef)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
for (i = count; i < count_elts; i++)
|
||||
for (size_t i = count; i < count_elts; i++)
|
||||
{
|
||||
elt_list[i].coef *= d;
|
||||
}
|
||||
@ -942,7 +935,7 @@ get_secondary_in_species(char **t_ptr, LDBLE coef)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
get_num(char **t_ptr, LDBLE * num)
|
||||
get_num(const char **t_ptr, LDBLE * num)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/*
|
||||
* Function reads through a string looking for leading numeric field
|
||||
@ -962,7 +955,7 @@ get_num(char **t_ptr, LDBLE * num)
|
||||
{
|
||||
int i, decimal;
|
||||
char c;
|
||||
char *ptr1;
|
||||
char* ptr1;
|
||||
char token[MAX_LENGTH];
|
||||
|
||||
*num = 1.0;
|
||||
@ -1005,7 +998,7 @@ get_num(char **t_ptr, LDBLE * num)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
get_species(char **ptr)
|
||||
get_species(const char **cptr)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/* Function reads next species out of the equation, including optional
|
||||
@ -1013,26 +1006,26 @@ get_species(char **ptr)
|
||||
* store in trxn.token[count].
|
||||
*
|
||||
* Arguments:
|
||||
* **ptr input, points to the position in the equation to pick up the species.
|
||||
* **cptr input, points to the position in the equation to pick up the species.
|
||||
* output, points to the next character after the species charge.
|
||||
*
|
||||
*/
|
||||
char string[MAX_LENGTH];
|
||||
std::string string;
|
||||
int l;
|
||||
|
||||
if ((size_t) count_trxn + 1 > trxn.token.size())
|
||||
trxn.token.resize((size_t)count_trxn + 1);
|
||||
trxn.token.resize(count_trxn + 1);
|
||||
/* coefficient */
|
||||
if (get_coef(&(trxn.token[count_trxn].coef), ptr) == ERROR)
|
||||
if (get_coef(&(trxn.token[count_trxn].coef), cptr) == ERROR)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
/* name and charge */
|
||||
if (get_token(ptr, string, &trxn.token[count_trxn].z, &l) == ERROR)
|
||||
if (get_token(cptr, string, &trxn.token[count_trxn].z, &l) == ERROR)
|
||||
{
|
||||
return (ERROR);
|
||||
}
|
||||
trxn.token[count_trxn].name = string_hsave(string);
|
||||
trxn.token[count_trxn].name = string_hsave(string.c_str());
|
||||
/*
|
||||
trxn.token[count_trxn].z = 0;
|
||||
trxn.token[count_trxn].s = NULL;
|
||||
|
||||
@ -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();
|
||||
@ -78,22 +72,9 @@ pitzer_tidy(void)
|
||||
/*
|
||||
* allocate other arrays for Pitzer
|
||||
*/
|
||||
if (IPRSNT != NULL)
|
||||
IPRSNT = (int *) free_check_null(IPRSNT);
|
||||
IPRSNT = (int *) PHRQ_malloc((size_t) (3 * s.size() * sizeof(int)));
|
||||
if (IPRSNT == NULL)
|
||||
malloc_error();
|
||||
if (M != NULL)
|
||||
M = (LDBLE *) free_check_null(M);
|
||||
M = (LDBLE *) PHRQ_malloc((size_t) (3 * s.size() * sizeof(LDBLE)));
|
||||
if (M == NULL)
|
||||
malloc_error();
|
||||
if (LGAMMA != NULL)
|
||||
LGAMMA = (LDBLE *) free_check_null(LGAMMA);
|
||||
LGAMMA = (LDBLE *) PHRQ_malloc((size_t) (3 * s.size() * sizeof(LDBLE)));
|
||||
if (LGAMMA == NULL)
|
||||
malloc_error();
|
||||
|
||||
IPRSNT.resize(3 * s.size());
|
||||
M.resize(3 * s.size());
|
||||
LGAMMA.resize(3 * s.size());
|
||||
|
||||
for (i = 0; i < (int)s.size(); i++)
|
||||
{
|
||||
@ -129,7 +110,7 @@ pitzer_tidy(void)
|
||||
{
|
||||
if (pitz_params_temp[i]->type == TYPE_ETHETA)
|
||||
{
|
||||
pitz_params_temp[i] = (struct pitz_param*)free_check_null(pitz_params_temp[i]);
|
||||
delete pitz_params_temp[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -171,9 +152,7 @@ pitzer_tidy(void)
|
||||
continue;
|
||||
pitz_params[i]->ispec[j] = ISPEC(pitz_params[i]->species[j]);
|
||||
if ((j < 2 && pitz_params[i]->ispec[j] == -1) ||
|
||||
(j == 2
|
||||
&& (pitz_params[i]->type == TYPE_PSI
|
||||
|| pitz_params[i]->type == TYPE_ZETA)
|
||||
(j == 2 && (pitz_params[i]->type == TYPE_PSI || pitz_params[i]->type == TYPE_ZETA)
|
||||
&& pitz_params[i]->ispec[j] == -1))
|
||||
{
|
||||
input_error++;
|
||||
@ -317,7 +296,7 @@ pitzer_tidy(void)
|
||||
|
||||
for (i = 0; i < (int)theta_params.size(); i++)
|
||||
{
|
||||
theta_params[i] = (struct theta_param *) free_check_null(theta_params[i]);
|
||||
delete theta_params[i];
|
||||
}
|
||||
theta_params.clear();
|
||||
for (i = 0; i < (int)pitz_params.size(); i++)
|
||||
@ -331,8 +310,7 @@ pitzer_tidy(void)
|
||||
{
|
||||
size_t count_theta_param = theta_params.size();
|
||||
theta_params.resize(count_theta_param + 1);
|
||||
theta_params[count_theta_param] = theta_param_alloc();
|
||||
theta_param_init(theta_params[count_theta_param]);
|
||||
theta_params[count_theta_param] = new struct theta_param;
|
||||
theta_params[count_theta_param]->zj = z0;
|
||||
theta_params[count_theta_param]->zk = z1;
|
||||
theta_param_ptr = theta_params[count_theta_param];
|
||||
@ -590,7 +568,7 @@ read_pitzer(void)
|
||||
pitz_param_type pzp_type;
|
||||
|
||||
int return_value, opt, opt_save;
|
||||
char *next_char;
|
||||
const char* next_char;
|
||||
const char *opt_list[] = {
|
||||
"b0", /* 0 */
|
||||
"b1", /* 1 */
|
||||
@ -643,12 +621,12 @@ read_pitzer(void)
|
||||
pzp_ptr->type = pzp_type;
|
||||
if (pzp_type == TYPE_APHI)
|
||||
{
|
||||
aphi = (struct pitz_param *) free_check_null(aphi);
|
||||
delete aphi;
|
||||
aphi = pzp_ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
pitz_param_store(pzp_ptr, false);
|
||||
pitz_param_store(pzp_ptr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1649,22 +1627,24 @@ pitzer_clean_up(void)
|
||||
int i;
|
||||
for (i = 0; i < (int)pitz_params.size(); i++)
|
||||
{
|
||||
pitz_params[i] =
|
||||
(struct pitz_param *) free_check_null(pitz_params[i]);
|
||||
delete pitz_params[i];
|
||||
}
|
||||
pitz_param_map.clear();
|
||||
pitz_params.clear();
|
||||
for (i = 0; i < (int)theta_params.size(); i++)
|
||||
{
|
||||
theta_params[i] =
|
||||
(struct theta_param *) free_check_null(theta_params[i]);
|
||||
delete theta_params[i];
|
||||
}
|
||||
theta_params.clear();
|
||||
LGAMMA = (LDBLE *) free_check_null(LGAMMA);
|
||||
IPRSNT = (int *) free_check_null(IPRSNT);
|
||||
spec = (struct species **) free_check_null(spec);
|
||||
aphi = (struct pitz_param *) free_check_null(aphi);
|
||||
M = (LDBLE *) free_check_null(M);
|
||||
LGAMMA.clear();
|
||||
IPRSNT.clear();
|
||||
spec.clear();
|
||||
if (aphi != NULL)
|
||||
{
|
||||
delete aphi;
|
||||
aphi = NULL;
|
||||
}
|
||||
M.clear();
|
||||
|
||||
return OK;
|
||||
}
|
||||
@ -1959,13 +1939,13 @@ int Phreeqc::
|
||||
jacobian_pz(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{ // calculate the derivatives numerically
|
||||
LDBLE *base;
|
||||
std::vector<double> base;
|
||||
LDBLE d, d1, d2;
|
||||
int i, j;
|
||||
|
||||
calculating_deriv = 1;
|
||||
Restart:
|
||||
int pz_max_unknowns = max_unknowns;
|
||||
size_t pz_max_unknowns = max_unknowns;
|
||||
//k_temp(tc_x, patm_x);
|
||||
if (full_pitzer == TRUE)
|
||||
{
|
||||
@ -1973,9 +1953,7 @@ Restart:
|
||||
pitzer();
|
||||
residuals();
|
||||
}
|
||||
base = (LDBLE *) PHRQ_malloc((size_t) count_unknowns * sizeof(LDBLE));
|
||||
if (base == NULL)
|
||||
malloc_error();
|
||||
base.resize(count_unknowns);
|
||||
for (i = 0; i < count_unknowns; i++)
|
||||
{
|
||||
base[i] = residual[i];
|
||||
@ -2073,7 +2051,7 @@ Restart:
|
||||
molalities(TRUE);
|
||||
if (max_unknowns > pz_max_unknowns)
|
||||
{
|
||||
base = (LDBLE *) free_check_null(base);
|
||||
base.clear();
|
||||
gammas_pz(false);
|
||||
jacobian_sums();
|
||||
goto Restart;
|
||||
@ -2084,9 +2062,9 @@ Restart:
|
||||
residuals();
|
||||
for (j = 0; j < count_unknowns; j++)
|
||||
{
|
||||
my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] = -(residual[j] - base[j]) / d2;
|
||||
my_array[(size_t)j * (count_unknowns + 1) + (size_t)i] = -(residual[j] - base[j]) / d2;
|
||||
if (x[i]->type == MH2O) // DL_pitz
|
||||
my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] *= mass_water_aq_x;
|
||||
my_array[(size_t)j * (count_unknowns + 1) + (size_t)i] *= mass_water_aq_x;
|
||||
}
|
||||
switch (x[i]->type)
|
||||
{
|
||||
@ -2104,9 +2082,9 @@ Restart:
|
||||
break;
|
||||
case MH:
|
||||
s_eminus->la -= d;
|
||||
if (my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i] == 0)
|
||||
if (my_array[(size_t)i * (count_unknowns + 1) + (size_t)i] == 0)
|
||||
{
|
||||
my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i] =
|
||||
my_array[(size_t)i * (count_unknowns + 1) + (size_t)i] =
|
||||
exp(s_h2->lm * LOG_10) * 2;
|
||||
}
|
||||
break;
|
||||
@ -2144,7 +2122,7 @@ Restart:
|
||||
pitzer();
|
||||
mb_sums();
|
||||
residuals();
|
||||
free_check_null(base);
|
||||
base.clear();
|
||||
calculating_deriv = 0;
|
||||
return OK;
|
||||
}
|
||||
@ -2461,12 +2439,12 @@ gammas_pz(bool exch_a_f)
|
||||
* Find moles of sites.
|
||||
* s_x[i]->equiv is stoichiometric coefficient of sites in species
|
||||
*/
|
||||
for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++)
|
||||
for (j = 1; s_x[i]->rxn_x.token[j].s != NULL; j++)
|
||||
{
|
||||
if (s_x[i]->rxn_x->token[j].s->type == SURF)
|
||||
if (s_x[i]->rxn_x.token[j].s->type == SURF)
|
||||
{
|
||||
s_x[i]->alk =
|
||||
s_x[i]->rxn_x->token[j].s->primary->unknown->moles;
|
||||
s_x[i]->rxn_x.token[j].s->primary->unknown->moles;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -2533,11 +2511,11 @@ gammas_pz(bool exch_a_f)
|
||||
* Find CEC
|
||||
* z contains valence of cation for exchange species, alk contains cec
|
||||
*/
|
||||
for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++)
|
||||
for (j = 1; s_x[i]->rxn_x.token[j].s != NULL; j++)
|
||||
{
|
||||
if (s_x[i]->rxn_x->token[j].s->type == EX)
|
||||
if (s_x[i]->rxn_x.token[j].s->type == EX)
|
||||
{
|
||||
s_x[i]->alk = s_x[i]->rxn_x->token[j].s->primary->unknown->moles;
|
||||
s_x[i]->alk = s_x[i]->rxn_x.token[j].s->primary->unknown->moles;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -2561,12 +2539,12 @@ gammas_pz(bool exch_a_f)
|
||||
if (use.Get_exchange_ptr()->Get_pitzer_exchange_gammas())
|
||||
{
|
||||
/* Assume equal gamma's of solute and exchangeable species... */
|
||||
for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++)
|
||||
for (j = 1; s_x[i]->rxn_x.token[j].s != NULL; j++)
|
||||
{
|
||||
if (s_x[i]->rxn_x->token[j].s->type == EX)
|
||||
if (s_x[i]->rxn_x.token[j].s->type == EX)
|
||||
continue;
|
||||
coef = s_x[i]->rxn_x->token[j].coef;
|
||||
s_x[i]->lg += coef * s_x[i]->rxn_x->token[j].s->lg;
|
||||
coef = s_x[i]->rxn_x.token[j].coef;
|
||||
s_x[i]->lg += coef * s_x[i]->rxn_x.token[j].s->lg;
|
||||
}
|
||||
}
|
||||
if (s_x[i]->a_f && s_x[i]->primary == NULL && s_x[i]->moles)
|
||||
|
||||
@ -9,53 +9,6 @@
|
||||
* Routines related to structure "pitz_param"
|
||||
*
|
||||
* ********************************************************************** */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct pitz_param * Phreeqc::
|
||||
pitz_param_alloc(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
struct pitz_param *pitz_param_ptr;
|
||||
pitz_param_ptr =
|
||||
(struct pitz_param *) PHRQ_malloc(sizeof(struct pitz_param));
|
||||
if (pitz_param_ptr == NULL)
|
||||
malloc_error();
|
||||
return (pitz_param_ptr);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
pitz_param_init(struct pitz_param *pitz_param_ptr)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
int i;
|
||||
/*
|
||||
* Frees all data associated with pitz_param structure.
|
||||
*/
|
||||
|
||||
if (pitz_param_ptr == NULL)
|
||||
return (ERROR);
|
||||
pitz_param_ptr->species[0] = NULL;
|
||||
pitz_param_ptr->species[1] = NULL;
|
||||
pitz_param_ptr->species[2] = NULL;
|
||||
pitz_param_ptr->ispec[0] = -1;
|
||||
pitz_param_ptr->ispec[1] = -1;
|
||||
pitz_param_ptr->ispec[2] = -1;
|
||||
pitz_param_ptr->type = TYPE_Other;
|
||||
pitz_param_ptr->p = 0.0;
|
||||
pitz_param_ptr->U.b0 = 0.0;
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
pitz_param_ptr->a[i] = 0.0;
|
||||
}
|
||||
pitz_param_ptr->alpha = 0.0;
|
||||
pitz_param_ptr->thetas = NULL;
|
||||
pitz_param_ptr->os_coef = 0.;
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
pitz_param_ptr->ln_coef[i] = 0.0;
|
||||
}
|
||||
return (OK);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct pitz_param * Phreeqc::
|
||||
@ -68,7 +21,7 @@ pitz_param_read(char *string, int n)
|
||||
*
|
||||
*/
|
||||
int l, i, j, k;
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
char token[2 * MAX_LENGTH];
|
||||
struct pitz_param pzp, *pzp_ptr;
|
||||
|
||||
@ -77,14 +30,13 @@ pitz_param_read(char *string, int n)
|
||||
if (string == NULL)
|
||||
return (NULL);
|
||||
|
||||
pitz_param_init(&pzp);
|
||||
ptr = string;
|
||||
if (copy_token(token, &ptr, &l) == EMPTY)
|
||||
cptr = string;
|
||||
if (copy_token(token, &cptr, &l) == EMPTY)
|
||||
return (NULL);
|
||||
ptr = string;
|
||||
cptr = string;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
int j = copy_token(token, &ptr, &l);
|
||||
int j = copy_token(token, &cptr, &l);
|
||||
if (j == EMPTY)
|
||||
return (NULL);
|
||||
if (j != UPPER && token[0] != '(')
|
||||
@ -99,7 +51,7 @@ pitz_param_read(char *string, int n)
|
||||
k = 0;
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
if (copy_token(token, &ptr, &l) == EMPTY)
|
||||
if (copy_token(token, &cptr, &l) == EMPTY)
|
||||
break;
|
||||
j = sscanf(token, SCANFORMAT, &pzp.a[i]);
|
||||
if (j <= 0)
|
||||
@ -108,48 +60,13 @@ pitz_param_read(char *string, int n)
|
||||
}
|
||||
if (k <= 0)
|
||||
return (NULL);
|
||||
pzp_ptr = pitz_param_duplicate(&pzp);
|
||||
pzp_ptr = new struct pitz_param;
|
||||
*pzp_ptr = pzp;
|
||||
return (pzp_ptr);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct pitz_param * Phreeqc::
|
||||
pitz_param_duplicate(struct pitz_param *old_ptr)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Allocates space and makes duplicate copy of pitz_param structure
|
||||
*/
|
||||
struct pitz_param *new_ptr;
|
||||
|
||||
new_ptr = pitz_param_alloc();
|
||||
pitz_param_init(new_ptr);
|
||||
/*
|
||||
* Copy data
|
||||
*/
|
||||
pitz_param_copy(old_ptr, new_ptr);
|
||||
return (new_ptr);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
pitz_param_copy(struct pitz_param *old_ptr, struct pitz_param *new_ptr)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Copies pitz_param data from old_ptr to new location, new_ptr.
|
||||
* Space for the new_ptr structure must already be malloced.
|
||||
*/
|
||||
/*
|
||||
* Store data for structure pitz_param
|
||||
*/
|
||||
memcpy(new_ptr, old_ptr, sizeof(struct pitz_param));
|
||||
return (OK);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void Phreeqc::
|
||||
pitz_param_store(struct pitz_param *pzp_ptr, bool force_copy)
|
||||
pitz_param_store(const struct pitz_param *pzp_ptr)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -161,7 +78,7 @@ pitz_param_store(struct pitz_param *pzp_ptr, bool force_copy)
|
||||
return;
|
||||
if (pzp_ptr->type == TYPE_Other)
|
||||
return;
|
||||
|
||||
struct pitz_param* dest = pitz_param_copy(pzp_ptr);
|
||||
std::set< std::string > header;
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
@ -190,42 +107,21 @@ pitz_param_store(struct pitz_param *pzp_ptr, bool force_copy)
|
||||
pzp_ptr->species[0], pzp_ptr->species[1]);
|
||||
}
|
||||
warning_msg(error_string);
|
||||
pitz_params[(*jit).second] = (struct pitz_param *) free_check_null(pitz_params[(*jit).second]);
|
||||
pitz_params[(*jit).second] = pzp_ptr;
|
||||
delete pitz_params[(*jit).second];
|
||||
pitz_params[(*jit).second] = dest;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (force_copy)
|
||||
{
|
||||
size_t count_pitz_param = pitz_params.size();
|
||||
pitz_params.resize(count_pitz_param + 1);
|
||||
pitz_params[count_pitz_param] = pitz_param_duplicate(pzp_ptr);
|
||||
// clean up pointers
|
||||
// species
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
if (pzp_ptr->species[i] != NULL)
|
||||
{
|
||||
pitz_params[count_pitz_param]->species[i] = string_hsave(pzp_ptr->species[i]);
|
||||
}
|
||||
}
|
||||
// thetas
|
||||
pitz_params[count_pitz_param]->thetas = NULL;
|
||||
pitz_param_map[key] = count_pitz_param;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t count_pitz_param = pitz_params.size();
|
||||
pitz_params.resize(count_pitz_param + 1);
|
||||
pitz_params[count_pitz_param] = pzp_ptr;
|
||||
pitz_param_map[key] = count_pitz_param;
|
||||
}
|
||||
size_t count_pitz_param = pitz_params.size();
|
||||
pitz_params.resize(count_pitz_param + 1);
|
||||
pitz_params[count_pitz_param] = pitz_param_copy(pzp_ptr);
|
||||
pitz_param_map[key] = count_pitz_param;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
void Phreeqc::
|
||||
sit_param_store(struct pitz_param *pzp_ptr, bool force_copy)
|
||||
sit_param_store(const struct pitz_param *pzp_ptr)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -237,6 +133,7 @@ sit_param_store(struct pitz_param *pzp_ptr, bool force_copy)
|
||||
return;
|
||||
if (pzp_ptr->type == TYPE_Other)
|
||||
return;
|
||||
struct pitz_param* dest = pitz_param_copy(pzp_ptr);
|
||||
|
||||
std::set< std::string > header;
|
||||
for (i = 0; i < 3; i++)
|
||||
@ -267,37 +164,32 @@ sit_param_store(struct pitz_param *pzp_ptr, bool force_copy)
|
||||
pzp_ptr->species[0], pzp_ptr->species[1]);
|
||||
}
|
||||
warning_msg(error_string);
|
||||
sit_params[(*jit).second] = (struct pitz_param *) free_check_null(sit_params[(*jit).second]);
|
||||
sit_params[(*jit).second] = pzp_ptr;
|
||||
delete sit_params[(*jit).second];
|
||||
sit_params[(*jit).second] = dest;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (force_copy)
|
||||
size_t count_sit_param = sit_params.size();
|
||||
sit_params.resize(count_sit_param + 1);
|
||||
sit_params[count_sit_param] = dest;
|
||||
sit_param_map[key] = count_sit_param;
|
||||
}
|
||||
}
|
||||
struct pitz_param* Phreeqc::
|
||||
pitz_param_copy(const struct pitz_param* src)
|
||||
{
|
||||
if (src == NULL) return NULL;
|
||||
struct pitz_param* dest = new struct pitz_param;
|
||||
*dest = *src;
|
||||
for (size_t i = 0; i < 3; i++)
|
||||
{
|
||||
if (src->species[i] != NULL)
|
||||
{
|
||||
size_t count_sit_param = sit_params.size();
|
||||
sit_params.resize(count_sit_param + 1);
|
||||
sit_params[count_sit_param] = pitz_param_duplicate(pzp_ptr);
|
||||
// clean up pointers
|
||||
// species
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
if (pzp_ptr->species[i] != NULL)
|
||||
{
|
||||
sit_params[count_sit_param]->species[i] = string_hsave(pzp_ptr->species[i]);
|
||||
}
|
||||
}
|
||||
// thetas
|
||||
sit_params[count_sit_param]->thetas = NULL;
|
||||
sit_param_map[key] = count_sit_param;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t count_sit_param = sit_params.size();
|
||||
sit_params.resize(count_sit_param + 1);
|
||||
sit_params[count_sit_param] = pzp_ptr;
|
||||
sit_param_map[key] = count_sit_param;
|
||||
dest->species[i] = string_hsave(src->species[i]);
|
||||
}
|
||||
}
|
||||
dest->thetas = NULL;
|
||||
return dest;
|
||||
}
|
||||
|
||||
/* **********************************************************************
|
||||
@ -305,37 +197,6 @@ sit_param_store(struct pitz_param *pzp_ptr, bool force_copy)
|
||||
* Routines related to structure "theta_parm"
|
||||
*
|
||||
* ********************************************************************** */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct theta_param * Phreeqc::
|
||||
theta_param_alloc(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
struct theta_param *theta_param_ptr;
|
||||
theta_param_ptr =
|
||||
(struct theta_param *) PHRQ_malloc(sizeof(struct theta_param));
|
||||
if (theta_param_ptr == NULL)
|
||||
malloc_error();
|
||||
return (theta_param_ptr);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
theta_param_init(struct theta_param *theta_param_ptr)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Frees all data associated with theta_param structure.
|
||||
*/
|
||||
|
||||
if (theta_param_ptr == NULL)
|
||||
return (ERROR);
|
||||
theta_param_ptr->zj = 0;
|
||||
theta_param_ptr->zk = 0;
|
||||
theta_param_ptr->etheta = 0;
|
||||
theta_param_ptr->ethetap = 0;
|
||||
return (OK);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
struct theta_param * Phreeqc::
|
||||
theta_param_search(LDBLE zj, LDBLE zk)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -597,7 +597,7 @@ print_gas_phase(void)
|
||||
print_centered("Gas phase");
|
||||
output_msg(sformatf("Total pressure: %5.2f atmospheres",
|
||||
(double) gas_phase_ptr->Get_total_p()));
|
||||
if (gas_phase_ptr->Get_total_p() >= MAX_P_NONLLNL && llnl_count_temp <= 0)
|
||||
if (gas_phase_ptr->Get_total_p() >= MAX_P_NONLLNL && llnl_temp.size() == 0)
|
||||
output_msg(" WARNING: Program limit.\n");
|
||||
else if (PR)
|
||||
output_msg(" (Peng-Robinson calculation)\n");
|
||||
@ -648,7 +648,7 @@ print_gas_phase(void)
|
||||
{
|
||||
lp = -phase_ptr->lk;
|
||||
for (rxn_ptr =
|
||||
phase_ptr->rxn_x->token + 1;
|
||||
&phase_ptr->rxn_x.token[0] + 1;
|
||||
rxn_ptr->s != NULL; rxn_ptr++)
|
||||
{
|
||||
lp += rxn_ptr->s->la * rxn_ptr->coef;
|
||||
@ -1073,7 +1073,7 @@ print_master_reactions(void)
|
||||
{
|
||||
output_msg(sformatf("%s\t%s\n\tPrimary reaction\n",
|
||||
master[i]->elt->name, master[i]->s->name));
|
||||
next_token = master[i]->rxn_primary->token;
|
||||
next_token = master[i]->rxn_primary.token;
|
||||
for (; next_token->s != NULL; next_token++)
|
||||
{
|
||||
output_msg(sformatf("\t\t%s\t%f\n", next_token->s->name,
|
||||
@ -1082,7 +1082,7 @@ print_master_reactions(void)
|
||||
output_msg(sformatf("\n\tSecondary reaction:\n"));
|
||||
if (master[i]->rxn_secondary != NULL)
|
||||
{
|
||||
next_token = master[i]->rxn_secondary->token;
|
||||
next_token = master[i]->rxn_secondary.token;
|
||||
for (; next_token->s != NULL; next_token++)
|
||||
{
|
||||
output_msg(sformatf("\t\t%s\t%f\n",
|
||||
@ -1165,37 +1165,6 @@ print_mix(void)
|
||||
output_msg(sformatf("\n"));
|
||||
return (OK);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
print_reaction(struct reaction *rxn_ptr)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Debugging print of individual chemical reactions for
|
||||
* species or phases
|
||||
*/
|
||||
int j;
|
||||
struct rxn_token *next_token;
|
||||
|
||||
if (pr.use == FALSE || pr.all == FALSE)
|
||||
return (OK);
|
||||
|
||||
output_msg(sformatf("%s\t\n", rxn_ptr->token[0].s->name));
|
||||
output_msg(sformatf("\n\tlog k:\n"));
|
||||
for (j = 0; j < MAX_LOG_K_INDICES; j++)
|
||||
{
|
||||
output_msg(sformatf("\t%f", (double) rxn_ptr->logk[j]));
|
||||
}
|
||||
output_msg(sformatf("\n\nReaction:\n"));
|
||||
for (next_token = rxn_ptr->token; next_token->s != NULL; next_token++)
|
||||
{
|
||||
output_msg(sformatf("\t\t%s\t%f\n", next_token->s->name,
|
||||
(double) next_token->coef));
|
||||
}
|
||||
output_msg(sformatf("\n"));
|
||||
return (OK);
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
print_saturation_indices(void)
|
||||
@ -1209,7 +1178,7 @@ print_saturation_indices(void)
|
||||
LDBLE lk;
|
||||
LDBLE la_eminus;
|
||||
struct rxn_token *rxn_ptr;
|
||||
struct reaction *reaction_ptr;
|
||||
CReaction *reaction_ptr;
|
||||
bool gas = true;
|
||||
|
||||
if (pr.saturation_indices == FALSE || pr.all == FALSE)
|
||||
@ -1217,7 +1186,7 @@ print_saturation_indices(void)
|
||||
if (state == INITIAL_SOLUTION)
|
||||
{
|
||||
iap = 0;
|
||||
for (size_t tok = 1; tok < pe_x[default_pe_x].Get_tokens().size(); tok++)
|
||||
for (size_t tok = 1; tok < pe_x[default_pe_x].Get_tokens().size() - 1; tok++)
|
||||
{
|
||||
iap += pe_x[default_pe_x].Get_tokens()[tok].coef * pe_x[default_pe_x].Get_tokens()[tok].s->la;
|
||||
/* fprintf(output,"\t%s\t%f\t%f\n", rxn_ptr->s->name, rxn_ptr->coef, rxn_ptr->s->la ); */
|
||||
@ -1254,19 +1223,19 @@ print_saturation_indices(void)
|
||||
continue;
|
||||
/* check for solids and gases in equation */
|
||||
if (phases[i]->replaced)
|
||||
reaction_ptr = phases[i]->rxn_s;
|
||||
reaction_ptr = &phases[i]->rxn_s;
|
||||
else
|
||||
reaction_ptr = phases[i]->rxn;
|
||||
reaction_ptr = &phases[i]->rxn;
|
||||
/*
|
||||
* Print saturation index
|
||||
*/
|
||||
reaction_ptr->logk[delta_v] = calc_delta_v(reaction_ptr, true) -
|
||||
reaction_ptr->logk[delta_v] = calc_delta_v(*reaction_ptr, true) -
|
||||
phases[i]->logk[vm0];
|
||||
if (reaction_ptr->logk[delta_v])
|
||||
mu_terms_in_logk = true;
|
||||
lk = k_calc(reaction_ptr->logk, tk_x, patm_x * PASCAL_PER_ATM);
|
||||
iap = 0.0;
|
||||
for (rxn_ptr = reaction_ptr->token + 1; rxn_ptr->s != NULL;
|
||||
for (rxn_ptr = &reaction_ptr->token[0] + 1; rxn_ptr->s != NULL;
|
||||
rxn_ptr++)
|
||||
{
|
||||
if (rxn_ptr->s != s_eminus)
|
||||
@ -1356,7 +1325,7 @@ print_pp_assemblage(void)
|
||||
*/
|
||||
iap = 0.0;
|
||||
phase_ptr = x[j]->phase;
|
||||
if (x[j]->phase->rxn_x == NULL || phase_ptr->in == FALSE)
|
||||
if (x[j]->phase->rxn_x.token.size() == 0 || phase_ptr->in == FALSE)
|
||||
{
|
||||
output_msg(sformatf("%-18s%23s", x[j]->phase->name,
|
||||
"Element not present."));
|
||||
@ -1364,12 +1333,12 @@ print_pp_assemblage(void)
|
||||
else
|
||||
{
|
||||
phase_ptr = x[j]->phase;
|
||||
phase_ptr->rxn->logk[delta_v] = calc_delta_v(phase_ptr->rxn, true) -
|
||||
phase_ptr->rxn.logk[delta_v] = calc_delta_v(*&phase_ptr->rxn, true) -
|
||||
phase_ptr->logk[vm0];
|
||||
if (phase_ptr->rxn->logk[delta_v])
|
||||
if (phase_ptr->rxn.logk[delta_v])
|
||||
mu_terms_in_logk = true;
|
||||
lk = k_calc(phase_ptr->rxn->logk, tk_x, patm_x * PASCAL_PER_ATM);
|
||||
for (rxn_ptr = phase_ptr->rxn->token + 1; rxn_ptr->s != NULL;
|
||||
lk = k_calc(phase_ptr->rxn.logk, tk_x, patm_x * PASCAL_PER_ATM);
|
||||
for (rxn_ptr = &phase_ptr->rxn.token[0] + 1; rxn_ptr->s != NULL;
|
||||
rxn_ptr++)
|
||||
{
|
||||
if (rxn_ptr->s != s_eminus)
|
||||
@ -1383,7 +1352,7 @@ print_pp_assemblage(void)
|
||||
}
|
||||
si = -lk + iap;
|
||||
/*
|
||||
for (rxn_ptr = x[j]->phase->rxn_x->token + 1; rxn_ptr->s != NULL; rxn_ptr++) {
|
||||
for (rxn_ptr = x[j]->phase->rxn_x.token + 1; rxn_ptr->s != NULL; rxn_ptr++) {
|
||||
iap += rxn_ptr->s->la * rxn_ptr->coef;
|
||||
}
|
||||
si = -x[j]->phase->lk + iap;
|
||||
@ -1919,7 +1888,7 @@ print_surface_cd_music(void)
|
||||
charge2 = unknown_ptr2->f;
|
||||
}
|
||||
sum = 0;
|
||||
for (int k = 0; k < x[j]->count_comp_unknowns; k++)
|
||||
for (size_t k = 0; k < x[j]->comp_unknowns.size(); k++)
|
||||
{
|
||||
sum +=
|
||||
x[j]->comp_unknowns[k]->moles *
|
||||
@ -2360,7 +2329,7 @@ print_user_print(void)
|
||||
|
||||
if (pr.user_print == FALSE || pr.all == FALSE)
|
||||
return (OK);
|
||||
if (user_print->commands == NULL)
|
||||
if (user_print->commands.size() == 0)
|
||||
return (OK);
|
||||
kinetics_ptr = NULL;
|
||||
if (use.Get_kinetics_in() == TRUE)
|
||||
@ -2380,7 +2349,7 @@ print_user_print(void)
|
||||
{
|
||||
/* basic_renumber(user_print->commands, &user_print->linebase, &user_print->varbase, &user_print->loopbase); */
|
||||
if (basic_compile
|
||||
(user_print->commands, &user_print->linebase,
|
||||
(user_print->commands.c_str(), &user_print->linebase,
|
||||
&user_print->varbase, &user_print->loopbase) != 0)
|
||||
{
|
||||
error_msg("Fatal Basic error in USER_PRINT.", STOP);
|
||||
@ -3239,7 +3208,7 @@ punch_saturation_indices(void)
|
||||
* Print saturation index
|
||||
*/
|
||||
iap = 0.0;
|
||||
for (rxn_ptr = ((struct phase *) current_selected_output->Get_si()[i].second)->rxn_x->token + 1;
|
||||
for (rxn_ptr = &(((struct phase *) current_selected_output->Get_si()[i].second)->rxn_x.token[0]) + 1;
|
||||
rxn_ptr->s != NULL; rxn_ptr++)
|
||||
{
|
||||
iap += rxn_ptr->s->la * rxn_ptr->coef;
|
||||
@ -3345,12 +3314,12 @@ punch_user_punch(void)
|
||||
|
||||
struct rate * user_punch = current_user_punch->Get_rate();
|
||||
|
||||
if (user_punch->commands == NULL)
|
||||
if (user_punch->commands.c_str() == 0)
|
||||
return (OK);
|
||||
if (user_punch->new_def == TRUE)
|
||||
{
|
||||
if (basic_compile
|
||||
(user_punch->commands, &user_punch->linebase,
|
||||
(user_punch->commands.c_str(), &user_punch->linebase,
|
||||
&user_punch->varbase, &user_punch->loopbase) != 0)
|
||||
{
|
||||
error_msg("Fatal Basic error in USER_PUNCH.", STOP);
|
||||
@ -3539,7 +3508,7 @@ punch_user_graph(void)
|
||||
if (chart->Get_rate_new_def())
|
||||
{
|
||||
if (basic_compile
|
||||
(chart->Get_user_graph()->commands, &chart->Get_user_graph()->linebase,
|
||||
(chart->Get_user_graph()->commands.c_str(), &chart->Get_user_graph()->linebase,
|
||||
&chart->Get_user_graph()->varbase, &chart->Get_user_graph()->loopbase) != 0)
|
||||
{
|
||||
error_msg("Fatal Basic error in USER_GRAPH.", STOP);
|
||||
@ -3606,46 +3575,38 @@ print_alkalinity(void)
|
||||
* Prints description of solution, uses array species_list for
|
||||
* order of aqueous species.
|
||||
*/
|
||||
int i, j;
|
||||
struct species_list *alk_list;
|
||||
int count_alk_list;
|
||||
int j;
|
||||
std::vector<struct species_list> alk_list;
|
||||
LDBLE min;
|
||||
|
||||
if (pr.alkalinity == FALSE || pr.all == FALSE)
|
||||
return (OK);
|
||||
print_centered("Distribution of alkalinity");
|
||||
alk_list = (struct species_list *)
|
||||
PHRQ_malloc((s_x.size() * sizeof(struct species_list)));
|
||||
if (alk_list == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
return (OK);
|
||||
}
|
||||
alk_list.clear();
|
||||
j = 0;
|
||||
for (i = 0; i < (int)this->s_x.size(); i++)
|
||||
for (size_t i = 0; i < this->s_x.size(); i++)
|
||||
{
|
||||
if (s_x[i]->alk == 0.0)
|
||||
continue;
|
||||
alk_list.resize(alk_list.size() + 1);
|
||||
alk_list[j].master_s = s_hplus;
|
||||
alk_list[j].s = s_x[i];
|
||||
alk_list[j].coef = s_x[i]->alk;
|
||||
j++;
|
||||
}
|
||||
count_alk_list = j;
|
||||
min = fabs(censor * total_alkalinity / mass_water_aq_x);
|
||||
if (count_alk_list > 0)
|
||||
if (alk_list.size() > 0)
|
||||
{
|
||||
output_msg(sformatf("\t%26s%11.3e\n\n",
|
||||
"Total alkalinity (eq/kgw) = ",
|
||||
(double) (total_alkalinity / mass_water_aq_x)));
|
||||
output_msg(sformatf("\t%-15s%12s%12s%10s\n\n", "Species",
|
||||
"Alkalinity", "Molality", "Alk/Mol"));
|
||||
if (count_alk_list > 1) qsort(&alk_list[0], (size_t) count_alk_list,
|
||||
if (alk_list.size() > 1) qsort(&alk_list[0], alk_list.size(),
|
||||
(size_t) sizeof(struct species_list), species_list_compare_alk);
|
||||
for (i = 0; i < count_alk_list; i++)
|
||||
for (size_t i = 0; i < alk_list.size(); i++)
|
||||
{
|
||||
if (fabs
|
||||
(alk_list[i].s->alk * (alk_list[i].s->moles) /
|
||||
if (fabs(alk_list[i].s->alk * (alk_list[i].s->moles) /
|
||||
mass_water_aq_x) < min)
|
||||
continue;
|
||||
output_msg(sformatf("\t%-15s%12.3e%12.3e%10.2f\n",
|
||||
@ -3658,7 +3619,6 @@ print_alkalinity(void)
|
||||
}
|
||||
|
||||
output_msg(sformatf("\n"));
|
||||
alk_list = (struct species_list *) free_check_null(alk_list);
|
||||
return (OK);
|
||||
}
|
||||
|
||||
|
||||
1993
phreeqcpp/read.cpp
1993
phreeqcpp/read.cpp
File diff suppressed because it is too large
Load Diff
@ -35,18 +35,16 @@ read_transport(void)
|
||||
* ERROR if error occurred reading data
|
||||
*
|
||||
*/
|
||||
char *ptr;
|
||||
int i, j, l;
|
||||
int count_length, count_disp, count_punch, count_print, count_por, count_same_model;
|
||||
int count_length_alloc, count_disp_alloc, count_por_alloc;
|
||||
char token[MAX_LENGTH];
|
||||
char *description;
|
||||
int n_user, n_user_end;
|
||||
LDBLE *length, *disp, *pors;
|
||||
int *punch_temp, *print_temp, *same_model_temp;
|
||||
int return_value, opt, opt_save;
|
||||
char *next_char, *next_char_save;
|
||||
char file_name[MAX_LENGTH];
|
||||
const char* next_char;
|
||||
//char file_name[MAX_LENGTH];
|
||||
std::string file_name("phreeqc.dmp");
|
||||
|
||||
const char *opt_list[] = {
|
||||
"cells", /* 0 */
|
||||
@ -100,7 +98,6 @@ read_transport(void)
|
||||
};
|
||||
int count_opt_list = 48;
|
||||
|
||||
strcpy(file_name, "phreeqc.dmp");
|
||||
/*
|
||||
* Initialize
|
||||
*/
|
||||
@ -143,12 +140,6 @@ read_transport(void)
|
||||
count_length_alloc = count_disp_alloc = count_por_alloc = 1;
|
||||
transport_start = 1;
|
||||
/*
|
||||
* Read transport number (not currently used)
|
||||
*/
|
||||
ptr = line;
|
||||
read_number_description(ptr, &n_user, &n_user_end, &description);
|
||||
description = (char *)free_check_null(description);
|
||||
/*
|
||||
* Set use data to last read
|
||||
*/
|
||||
use.Set_trans_in(true);
|
||||
@ -376,7 +367,7 @@ read_transport(void)
|
||||
if (copy_token(token, &next_char, &l) != EMPTY)
|
||||
{
|
||||
/* exchange factor */
|
||||
if (sscanf(token, "%d", &(stag_data->count_stag)) != 1)
|
||||
if (sscanf(token, "%d", &(stag_data.count_stag)) != 1)
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
@ -389,7 +380,7 @@ read_transport(void)
|
||||
j = copy_token(token, &next_char, &l);
|
||||
if (j != EMPTY)
|
||||
{
|
||||
if (sscanf(token, SCANFORMAT, &(stag_data->exch_f)) != 1)
|
||||
if (sscanf(token, SCANFORMAT, &(stag_data.exch_f)) != 1)
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
@ -398,7 +389,7 @@ read_transport(void)
|
||||
break;
|
||||
}
|
||||
copy_token(token, &next_char, &l);
|
||||
if (sscanf(token, SCANFORMAT, &(stag_data->th_m)) != 1)
|
||||
if (sscanf(token, SCANFORMAT, &(stag_data.th_m)) != 1)
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
@ -407,7 +398,7 @@ read_transport(void)
|
||||
break;
|
||||
}
|
||||
copy_token(token, &next_char, &l);
|
||||
if (sscanf(token, SCANFORMAT, &(stag_data->th_im)) != 1)
|
||||
if (sscanf(token, SCANFORMAT, &(stag_data.th_im)) != 1)
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
@ -442,17 +433,17 @@ read_transport(void)
|
||||
opt_save = OPTION_DEFAULT;
|
||||
break;
|
||||
case 26: /* dump */
|
||||
{
|
||||
dump_in = TRUE;
|
||||
next_char_save = next_char;
|
||||
if (copy_token(file_name, &next_char, &l) == EMPTY)
|
||||
strcpy(file_name, "phreeqc.dmp");
|
||||
else
|
||||
std::string temp_name(next_char);
|
||||
string_trim(temp_name);
|
||||
if (temp_name.size() > 0)
|
||||
{
|
||||
string_trim(next_char_save);
|
||||
strcpy(file_name, next_char_save);
|
||||
file_name = temp_name;
|
||||
}
|
||||
opt_save = OPTION_DEFAULT;
|
||||
break;
|
||||
}
|
||||
case 27: /* output */
|
||||
case 28: /* output_frequency */
|
||||
case 34: /* print_frequency */
|
||||
@ -744,8 +735,8 @@ read_transport(void)
|
||||
max_cells = count_length;
|
||||
if (count_disp > max_cells)
|
||||
max_cells = count_disp;
|
||||
if (count_por > max_cells * (1 + stag_data->count_stag))
|
||||
max_cells = (int)ceil(((double)count_por / (1 + (double)stag_data->count_stag)));
|
||||
if (count_por > max_cells * (1 + stag_data.count_stag))
|
||||
max_cells = (int)ceil(((double)count_por / (1 + (double)stag_data.count_stag)));
|
||||
if (max_cells > count_cells)
|
||||
{
|
||||
if (max_cells == count_length)
|
||||
@ -766,18 +757,16 @@ read_transport(void)
|
||||
{
|
||||
sprintf(token,
|
||||
"Number of mobile cells is increased to (ceil)(number of porosities) / (1 + number of stagnant zones) = %d.",
|
||||
(int) ceil(((double)count_por / (1 + (double)stag_data->count_stag))));
|
||||
(int) ceil(((double)count_por / (1 + (double)stag_data.count_stag))));
|
||||
warning_msg(token);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Allocate space for cell_data
|
||||
*/
|
||||
int all_cells_now = max_cells * (1 + stag_data->count_stag) + 2;
|
||||
space((void **)((void *)&cell_data), all_cells_now, &cell_data_max_cells,
|
||||
sizeof(struct cell_data));
|
||||
|
||||
// initialize new cells
|
||||
int all_cells_now = max_cells * (1 + stag_data.count_stag) + 2;
|
||||
cell_data.resize(all_cells_now); // initialized by global_structures.h
|
||||
// But first two previously allocated
|
||||
if (all_cells_now > all_cells)
|
||||
{
|
||||
for (int i = all_cells; i < all_cells_now; i++)
|
||||
@ -822,7 +811,7 @@ read_transport(void)
|
||||
"Cell-lengths were read for %d cells. Last value is used till cell %d.",
|
||||
count_length, max_cells);
|
||||
warning_msg(error_string);
|
||||
for (i = count_length; i <= max_cells; i++)
|
||||
for (size_t i = count_length; i <= max_cells; i++)
|
||||
cell_data[i + 1].length = length[count_length - 1];
|
||||
}
|
||||
}
|
||||
@ -888,15 +877,15 @@ read_transport(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1))
|
||||
if ((stag_data.exch_f > 0) && (stag_data.count_stag == 1))
|
||||
{
|
||||
error_string = sformatf(
|
||||
"Mobile porosities were read, but mobile/immobile porosity was also defined in -stagnant. Using the values from -stagnant for mobile/immobile exchange and tortuosity factors.");
|
||||
warning_msg(error_string);
|
||||
for (i = 1; i <= max_cells; i++)
|
||||
cell_data[i].por = stag_data->th_m;
|
||||
cell_data[i].por = stag_data.th_m;
|
||||
for (i++; i <= 2 * max_cells + 1; i++)
|
||||
cell_data[i].por = stag_data->th_im;
|
||||
cell_data[i].por = stag_data.th_im;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -908,7 +897,7 @@ read_transport(void)
|
||||
}
|
||||
if (all_cells - 2 > count_por)
|
||||
{
|
||||
int st = stag_data->count_stag ? 1 : 0;
|
||||
int st = stag_data.count_stag ? 1 : 0;
|
||||
error_string = sformatf(
|
||||
"Porosities were read for %d cells. Last value is used till cell %d.",
|
||||
count_por, all_cells - st);
|
||||
@ -943,12 +932,12 @@ read_transport(void)
|
||||
/*
|
||||
* Account for stagnant cells
|
||||
*/
|
||||
if (stag_data->count_stag > 0)
|
||||
if (stag_data.count_stag > 0)
|
||||
{
|
||||
max_cells = count_cells * (1 + stag_data->count_stag) + 2;
|
||||
max_cells = count_cells * (1 + stag_data.count_stag) + 2;
|
||||
for (i = 1; i <= count_cells; i++)
|
||||
{
|
||||
for (l = 1; l <= stag_data->count_stag; l++)
|
||||
for (l = 1; l <= stag_data.count_stag; l++)
|
||||
cell_data[i + 1 + l * count_cells].mid_cell_x =
|
||||
cell_data[i].mid_cell_x;
|
||||
}
|
||||
@ -1093,9 +1082,9 @@ read_transport(void)
|
||||
*/
|
||||
if (heat_diffc < 0)
|
||||
heat_diffc = diffc;
|
||||
else if (stag_data->count_stag == 1)
|
||||
else if (stag_data.count_stag == 1)
|
||||
{
|
||||
if (stag_data->exch_f > 0)
|
||||
if (stag_data.exch_f > 0)
|
||||
{
|
||||
if (diffc <= 0 && heat_diffc > 0)
|
||||
{
|
||||
@ -1123,7 +1112,7 @@ read_transport(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (stag_data->count_stag > 1 && heat_diffc > diffc)
|
||||
else if (stag_data.count_stag > 1 && heat_diffc > diffc)
|
||||
{
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
@ -1150,7 +1139,7 @@ read_transport(void)
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
read_line_LDBLEs(char *next_char, LDBLE ** d, int *count_d, int *count_alloc)
|
||||
read_line_LDBLEs(const char* next_char, LDBLE ** d, int *count_d, int *count_alloc)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
int i, j, l, n;
|
||||
|
||||
@ -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++)
|
||||
{
|
||||
@ -186,7 +177,7 @@ read_sit(void)
|
||||
pitz_param_type pzp_type;
|
||||
|
||||
int return_value, opt, opt_save;
|
||||
char *next_char;
|
||||
const char* next_char;
|
||||
const char *opt_list[] = {
|
||||
"epsilon", /* 0 */
|
||||
"epsilon1" /* 1 */
|
||||
@ -220,7 +211,7 @@ read_sit(void)
|
||||
if (pzp_ptr != NULL)
|
||||
{
|
||||
pzp_ptr->type = pzp_type;
|
||||
sit_param_store(pzp_ptr, false);
|
||||
sit_param_store(pzp_ptr);
|
||||
}
|
||||
break;
|
||||
case OPTION_ERROR:
|
||||
@ -505,15 +496,15 @@ sit_clean_up(void)
|
||||
|
||||
for (i = 0; i < (int)sit_params.size(); i++)
|
||||
{
|
||||
sit_params[i] = (struct pitz_param *) free_check_null(sit_params[i]);
|
||||
delete sit_params[i];
|
||||
}
|
||||
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);
|
||||
aphi = (struct pitz_param *) free_check_null(aphi);
|
||||
sit_M = (LDBLE *) free_check_null(sit_M);
|
||||
sit_LGAMMA.clear();
|
||||
sit_IPRSNT.clear();
|
||||
spec.clear();
|
||||
//delete aphi;
|
||||
sit_M.clear();
|
||||
|
||||
return OK;
|
||||
}
|
||||
@ -805,11 +796,11 @@ int Phreeqc::
|
||||
jacobian_sit(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
LDBLE *base;
|
||||
std::vector<double> base;
|
||||
LDBLE d, d1, d2;
|
||||
int i, j;
|
||||
Restart:
|
||||
int pz_max_unknowns = max_unknowns;
|
||||
size_t pz_max_unknowns = max_unknowns;
|
||||
//k_temp(tc_x, patm_x);
|
||||
if (full_pitzer == TRUE)
|
||||
{
|
||||
@ -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;
|
||||
@ -911,7 +892,7 @@ Restart:
|
||||
residuals();
|
||||
for (j = 0; j < count_unknowns; j++)
|
||||
{
|
||||
my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] =
|
||||
my_array[(size_t)j * (count_unknowns + 1) + (size_t)i] =
|
||||
-(residual[j] - base[j]) / d2;
|
||||
}
|
||||
switch (x[i]->type)
|
||||
@ -930,9 +911,9 @@ Restart:
|
||||
break;
|
||||
case MH:
|
||||
s_eminus->la -= d;
|
||||
if (my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i] == 0)
|
||||
if (my_array[(size_t)i * (count_unknowns + 1) + (size_t)i] == 0)
|
||||
{
|
||||
my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i] =
|
||||
my_array[(size_t)i * (count_unknowns + 1) + (size_t)i] =
|
||||
exp(s_h2->lm * LOG_10) * 2;
|
||||
}
|
||||
break;
|
||||
@ -960,7 +941,6 @@ Restart:
|
||||
sit();
|
||||
mb_sums();
|
||||
residuals();
|
||||
free_check_null(base);
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -1276,12 +1256,12 @@ gammas_sit()
|
||||
* Find moles of sites.
|
||||
* s_x[i]->equiv is stoichiometric coefficient of sites in species
|
||||
*/
|
||||
for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++)
|
||||
for (j = 1; s_x[i]->rxn_x.token[j].s != NULL; j++)
|
||||
{
|
||||
if (s_x[i]->rxn_x->token[j].s->type == SURF)
|
||||
if (s_x[i]->rxn_x.token[j].s->type == SURF)
|
||||
{
|
||||
s_x[i]->alk =
|
||||
s_x[i]->rxn_x->token[j].s->primary->unknown->moles;
|
||||
s_x[i]->rxn_x.token[j].s->primary->unknown->moles;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1341,12 +1321,12 @@ gammas_sit()
|
||||
* z contains valence of cation for exchange species, alk contains cec
|
||||
*/
|
||||
/* !!!!! */
|
||||
for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++)
|
||||
for (j = 1; s_x[i]->rxn_x.token[j].s != NULL; j++)
|
||||
{
|
||||
if (s_x[i]->rxn_x->token[j].s->type == EX)
|
||||
if (s_x[i]->rxn_x.token[j].s->type == EX)
|
||||
{
|
||||
s_x[i]->alk =
|
||||
s_x[i]->rxn_x->token[j].s->primary->unknown->
|
||||
s_x[i]->rxn_x.token[j].s->primary->unknown->
|
||||
moles;
|
||||
break;
|
||||
}
|
||||
@ -1372,13 +1352,13 @@ gammas_sit()
|
||||
if (use.Get_exchange_ptr()->Get_pitzer_exchange_gammas())
|
||||
{
|
||||
/* Assume equal gamma's of solute and exchangeable species... */
|
||||
for (j = 1; s_x[i]->rxn_x->token[j].s != NULL; j++)
|
||||
for (j = 1; s_x[i]->rxn_x.token[j].s != NULL; j++)
|
||||
{
|
||||
if (s_x[i]->rxn_x->token[j].s->type == EX)
|
||||
if (s_x[i]->rxn_x.token[j].s->type == EX)
|
||||
continue;
|
||||
coef = s_x[i]->rxn_x->token[j].coef;
|
||||
s_x[i]->lg += coef * s_x[i]->rxn_x->token[j].s->lg;
|
||||
s_x[i]->dg += coef * s_x[i]->rxn_x->token[j].s->dg;
|
||||
coef = s_x[i]->rxn_x.token[j].coef;
|
||||
s_x[i]->lg += coef * s_x[i]->rxn_x.token[j].s->lg;
|
||||
s_x[i]->dg += coef * s_x[i]->rxn_x.token[j].s->dg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,10 +37,10 @@ read_solution_spread(void)
|
||||
struct spread_row *heading, *row_ptr, *units;
|
||||
int count, strings, numbers;
|
||||
int spread_lines;
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
struct defaults soln_defaults;
|
||||
int return_value, opt;
|
||||
char *next_char;
|
||||
const char* next_char;
|
||||
const char *opt_list[] = {
|
||||
"temp", /* 0 */
|
||||
"temperature", /* 1 */
|
||||
@ -79,14 +79,11 @@ read_solution_spread(void)
|
||||
|
||||
|
||||
/* fill in soln_defaults.iso */
|
||||
soln_defaults.count_iso = count_iso_defaults;
|
||||
soln_defaults.iso = (struct iso *) PHRQ_malloc((size_t) soln_defaults.count_iso *
|
||||
sizeof(struct iso));
|
||||
if (soln_defaults.iso == NULL)
|
||||
malloc_error();
|
||||
soln_defaults.iso.resize(count_iso_defaults);
|
||||
|
||||
/* all iso[i].name is hsave'd, so no conflicts */
|
||||
memcpy(soln_defaults.iso, iso_defaults,
|
||||
(size_t) soln_defaults.count_iso * sizeof(struct iso));
|
||||
memcpy(&soln_defaults.iso[0], iso_defaults,
|
||||
soln_defaults.iso.size() * sizeof(struct iso));
|
||||
|
||||
heading = NULL;
|
||||
units = NULL;
|
||||
@ -103,10 +100,10 @@ read_solution_spread(void)
|
||||
if (spread_lines == 0 && opt != OPTION_DEFAULT)
|
||||
{
|
||||
row_ptr = string_to_spread_row(line);
|
||||
ptr = line;
|
||||
cptr = line;
|
||||
count = numbers = strings = 0;
|
||||
int j;
|
||||
while (((j = copy_token(token, &ptr)) != EMPTY))
|
||||
while (((j = copy_token(token, &cptr)) != EMPTY))
|
||||
{
|
||||
count++;
|
||||
if (j == UPPER || j == LOWER)
|
||||
@ -117,14 +114,16 @@ read_solution_spread(void)
|
||||
/*
|
||||
* Is 2nd token all number
|
||||
*/
|
||||
ptr = line;
|
||||
copy_token(token, &ptr);
|
||||
j = copy_token(token, &ptr);
|
||||
cptr = line;
|
||||
copy_token(token, &cptr);
|
||||
j = copy_token(token, &cptr);
|
||||
bool num = false;
|
||||
if (j == DIGIT)
|
||||
{
|
||||
strtod(token.c_str(), &ptr);
|
||||
int j1 = copy_token(token1, &ptr);
|
||||
char* ptr;
|
||||
(void)strtod(token.c_str(), &ptr);
|
||||
cptr = ptr;
|
||||
int j1 = copy_token(token1, &cptr);
|
||||
if (j1 != EMPTY)
|
||||
{
|
||||
num = FALSE;
|
||||
@ -134,12 +133,11 @@ read_solution_spread(void)
|
||||
num = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Starts with hyphen
|
||||
*/
|
||||
ptr = line;
|
||||
copy_token(token, &ptr);
|
||||
cptr = line;
|
||||
copy_token(token, &cptr);
|
||||
if (token[0] == '-')
|
||||
{
|
||||
/* opt = opt; */
|
||||
@ -367,29 +365,20 @@ read_solution_spread(void)
|
||||
error_msg(error_string, PHRQ_io::OT_CONTINUE);
|
||||
continue;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < soln_defaults.count_iso; i++)
|
||||
size_t i;
|
||||
for (i = 0; i < soln_defaults.iso.size(); i++)
|
||||
{
|
||||
if (strcmp(token.c_str(), soln_defaults.iso[i].name) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == soln_defaults.count_iso)
|
||||
if (i == soln_defaults.iso.size())
|
||||
{
|
||||
soln_defaults.iso = (struct iso *) PHRQ_realloc(soln_defaults.iso,
|
||||
((size_t)i + 1) * sizeof(struct iso));
|
||||
if (soln_defaults.iso == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
soln_defaults.iso[i].name = string_hsave(token.c_str());
|
||||
soln_defaults.iso[i].value = NAN;
|
||||
soln_defaults.iso[i].uncertainty = NAN;
|
||||
soln_defaults.count_iso++;
|
||||
}
|
||||
soln_defaults.iso.resize((size_t)i + 1);
|
||||
soln_defaults.iso[i].name = string_hsave(token.c_str());
|
||||
soln_defaults.iso[i].value = NAN;
|
||||
soln_defaults.iso[i].uncertainty = NAN;
|
||||
}
|
||||
|
||||
/* read and store isotope ratio uncertainty */
|
||||
@ -451,28 +440,19 @@ read_solution_spread(void)
|
||||
continue;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < soln_defaults.count_iso; i++)
|
||||
for (i = 0; i < soln_defaults.iso.size(); i++)
|
||||
{
|
||||
if (strcmp(token.c_str(), soln_defaults.iso[i].name) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == soln_defaults.count_iso)
|
||||
if (i == soln_defaults.iso.size())
|
||||
{
|
||||
soln_defaults.iso = (struct iso *) PHRQ_realloc(soln_defaults.iso,
|
||||
((size_t)i + 1) * sizeof(struct iso));
|
||||
if (soln_defaults.iso == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
soln_defaults.iso[i].name = string_hsave(token.c_str());
|
||||
soln_defaults.iso[i].value = NAN;
|
||||
soln_defaults.iso[i].uncertainty = NAN;
|
||||
soln_defaults.count_iso++;
|
||||
}
|
||||
soln_defaults.iso.resize((size_t)i + 1);
|
||||
soln_defaults.iso[i].name = string_hsave(token.c_str());
|
||||
soln_defaults.iso[i].value = NAN;
|
||||
soln_defaults.iso[i].uncertainty = NAN;
|
||||
}
|
||||
/* read and store isotope ratio */
|
||||
if (copy_token(token, &next_char) != DIGIT)
|
||||
@ -538,7 +518,7 @@ read_solution_spread(void)
|
||||
spread_row_free(heading);
|
||||
spread_row_free(units);
|
||||
|
||||
soln_defaults.iso = (struct iso *) free_check_null(soln_defaults.iso);
|
||||
soln_defaults.iso.clear();
|
||||
return (return_value);
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -554,7 +534,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
|
||||
CParser parser(this->phrq_io);
|
||||
|
||||
int return_value, opt;
|
||||
char *next_char;
|
||||
const char* next_char;
|
||||
const char *opt_list[] = {
|
||||
"temp", /* 0 */
|
||||
"temperature", /* 1 */
|
||||
@ -649,7 +629,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
|
||||
initial_data_ptr->Set_units(defaults.units);
|
||||
initial_data_ptr->Set_default_pe(defaults.redox);
|
||||
{
|
||||
cxxChemRxn temp_chem_reaction;
|
||||
CReaction temp_chem_reaction;
|
||||
initial_data_ptr->Get_pe_reactions()[defaults.redox] = temp_chem_reaction;
|
||||
}
|
||||
/*
|
||||
@ -761,7 +741,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
|
||||
{
|
||||
const char * pe_str = string_hsave(token.c_str());
|
||||
initial_data_ptr->Set_default_pe(pe_str);
|
||||
cxxChemRxn temp_chem_reaction;
|
||||
CReaction temp_chem_reaction;
|
||||
initial_data_ptr->Get_pe_reactions()[token] = temp_chem_reaction;
|
||||
}
|
||||
else
|
||||
@ -884,10 +864,10 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
|
||||
/* read and save element name */
|
||||
{
|
||||
char *temp_iso_name = string_duplicate(token.c_str());
|
||||
char *ptr1 = temp_iso_name;
|
||||
get_num(&ptr1, &dummy);
|
||||
const char* cptr1 = temp_iso_name;
|
||||
get_num(&cptr1, &dummy);
|
||||
temp_isotope.Set_isotope_number(dummy);
|
||||
if (ptr1[0] == '\0' || isupper((int) ptr1[0]) == FALSE)
|
||||
if (cptr1[0] == '\0' || isupper((int)cptr1[0]) == FALSE)
|
||||
{
|
||||
error_msg("Expecting element name.", PHRQ_io::OT_CONTINUE);
|
||||
error_msg(line_save, PHRQ_io::OT_CONTINUE);
|
||||
@ -896,7 +876,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
|
||||
char_string = (char*)free_check_null(char_string);
|
||||
return (CParser::PARSER_ERROR);
|
||||
}
|
||||
temp_isotope.Set_elt_name(ptr1);
|
||||
temp_isotope.Set_elt_name(cptr1);
|
||||
temp_iso_name = (char*)free_check_null(temp_iso_name);
|
||||
}
|
||||
/* read and store isotope ratio */
|
||||
@ -934,8 +914,6 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
|
||||
break;
|
||||
case 10: /* water */
|
||||
{
|
||||
//next_char = char_string;
|
||||
//int j = copy_token(token, &next_char); // read identifier "water"
|
||||
int j = copy_token(token, &next_char);
|
||||
if (j == EMPTY)
|
||||
{
|
||||
@ -1001,7 +979,7 @@ spread_row_to_solution(struct spread_row *heading, struct spread_row *units,
|
||||
initial_data_ptr->Get_comps()[temp_comp.Get_description()] = temp_comp;
|
||||
if (temp_comp.Get_pe_reaction().size() > 0)
|
||||
{
|
||||
cxxChemRxn temp_chem_reaction;
|
||||
CReaction temp_chem_reaction;
|
||||
initial_data_ptr->Get_pe_reactions()[temp_comp.Get_pe_reaction()] = temp_chem_reaction;
|
||||
}
|
||||
}
|
||||
@ -1058,158 +1036,59 @@ struct spread_row * Phreeqc::
|
||||
string_to_spread_row(char *string)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
int j, l;
|
||||
/* possible memory error if length of line is smaller than previous line */
|
||||
char *token;
|
||||
char *ptr;
|
||||
struct spread_row *spread_row_ptr = NULL;
|
||||
int j;
|
||||
std::string token;
|
||||
const char* cptr;
|
||||
/*
|
||||
* Allocate space
|
||||
*/
|
||||
token = (char *) PHRQ_malloc(strlen(line) + 1);
|
||||
if (token == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
return spread_row_ptr;
|
||||
}
|
||||
spread_row_ptr =
|
||||
(struct spread_row *) PHRQ_malloc((size_t) sizeof(struct spread_row));
|
||||
struct spread_row* spread_row_ptr = new struct spread_row;
|
||||
if (spread_row_ptr == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
return spread_row_ptr;
|
||||
}
|
||||
spread_row_ptr->char_vector =
|
||||
(char **) PHRQ_malloc((size_t) spread_length * sizeof(char *));
|
||||
if (spread_row_ptr->char_vector == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
return spread_row_ptr;
|
||||
}
|
||||
spread_row_ptr->d_vector =
|
||||
(LDBLE *) PHRQ_malloc((size_t) spread_length * sizeof(LDBLE));
|
||||
if (spread_row_ptr->d_vector == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
return spread_row_ptr;
|
||||
}
|
||||
spread_row_ptr->type_vector =
|
||||
(int *) PHRQ_malloc((size_t) spread_length * sizeof(int));
|
||||
if (spread_row_ptr->type_vector == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
return spread_row_ptr;
|
||||
}
|
||||
spread_row_ptr->count = 0;
|
||||
spread_row_ptr->empty = 0;
|
||||
spread_row_ptr->string = 0;
|
||||
spread_row_ptr->number = 0;
|
||||
ptr = string;
|
||||
cptr = string;
|
||||
/*
|
||||
* Split by tabs, reallocate space
|
||||
*/
|
||||
for (;;)
|
||||
{
|
||||
if (spread_row_ptr->count + 1 > spread_length)
|
||||
{
|
||||
spread_length *= 2;
|
||||
|
||||
spread_row_ptr->char_vector =
|
||||
(char **) PHRQ_realloc(spread_row_ptr->char_vector,
|
||||
(size_t) spread_length * sizeof(char *));
|
||||
if (spread_row_ptr->char_vector == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
return spread_row_ptr;
|
||||
}
|
||||
|
||||
spread_row_ptr->d_vector =
|
||||
(LDBLE *) PHRQ_realloc(spread_row_ptr->d_vector,
|
||||
(size_t) spread_length * sizeof(LDBLE));
|
||||
if (spread_row_ptr->d_vector == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
return spread_row_ptr;
|
||||
}
|
||||
|
||||
spread_row_ptr->type_vector =
|
||||
(int *) PHRQ_realloc(spread_row_ptr->type_vector,
|
||||
(size_t) spread_length * sizeof(int));
|
||||
if (spread_row_ptr->type_vector == NULL)
|
||||
{
|
||||
malloc_error();
|
||||
return spread_row_ptr;
|
||||
}
|
||||
}
|
||||
j = copy_token_tab(token, &ptr, &l);
|
||||
j = copy_token_tab(token, &cptr);
|
||||
if (j == EOL)
|
||||
break;
|
||||
spread_row_ptr->char_vector[spread_row_ptr->count] =
|
||||
string_duplicate(token);
|
||||
spread_row_ptr->d_vector[spread_row_ptr->count] = NAN;
|
||||
if (j == EMPTY || l == 0)
|
||||
spread_row_ptr->char_vector.push_back(string_duplicate(token.c_str()));
|
||||
spread_row_ptr->d_vector.push_back(NAN);
|
||||
if (j == EMPTY || token.size() == 0)
|
||||
{
|
||||
spread_row_ptr->empty++;
|
||||
spread_row_ptr->type_vector[spread_row_ptr->count] = EMPTY;
|
||||
spread_row_ptr->type_vector.push_back(EMPTY);
|
||||
}
|
||||
else if (j == UPPER || j == LOWER)
|
||||
{
|
||||
spread_row_ptr->string++;
|
||||
spread_row_ptr->type_vector[spread_row_ptr->count] = STRING;
|
||||
spread_row_ptr->type_vector.push_back(STRING);
|
||||
}
|
||||
else if (j == DIGIT)
|
||||
{
|
||||
spread_row_ptr->number++;
|
||||
spread_row_ptr->d_vector[spread_row_ptr->count] =
|
||||
strtod(token, NULL);
|
||||
spread_row_ptr->type_vector[spread_row_ptr->count] = NUMBER;
|
||||
spread_row_ptr->d_vector.push_back(strtod(token.c_str(), NULL));
|
||||
spread_row_ptr->type_vector.push_back(NUMBER);
|
||||
}
|
||||
else
|
||||
{
|
||||
input_error++;
|
||||
error_msg("Unknown input in string_to_spread_row keyword.", CONTINUE);
|
||||
error_string = sformatf("\tcopy_token j: %d, token: %s\n", j, token);
|
||||
error_string = sformatf("\tcopy_token j: %d, token: %s\n", j, token.c_str());
|
||||
error_msg(error_string, CONTINUE);
|
||||
error_msg(line_save, CONTINUE);
|
||||
}
|
||||
spread_row_ptr->count++;
|
||||
}
|
||||
/*
|
||||
* Clean up and return
|
||||
*/
|
||||
if (spread_row_ptr->count == 0)
|
||||
{
|
||||
spread_row_ptr->char_vector =
|
||||
(char **) free_check_null(spread_row_ptr->char_vector);
|
||||
spread_row_ptr->d_vector =
|
||||
(LDBLE *) free_check_null(spread_row_ptr->d_vector);
|
||||
spread_row_ptr->type_vector =
|
||||
(int *) free_check_null(spread_row_ptr->type_vector);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Do not realloc to smaller size, memory error */
|
||||
/*
|
||||
spread_row_ptr->char_vector =
|
||||
(char **) PHRQ_realloc (spread_row_ptr->char_vector,
|
||||
(size_t) spread_row_ptr->count *
|
||||
sizeof (char *));
|
||||
if (spread_row_ptr->char_vector == NULL)
|
||||
malloc_error ();
|
||||
spread_row_ptr->d_vector =
|
||||
(LDBLE *) PHRQ_realloc (spread_row_ptr->d_vector,
|
||||
(size_t) spread_row_ptr->count *
|
||||
sizeof (LDBLE));
|
||||
if (spread_row_ptr->d_vector == NULL)
|
||||
malloc_error ();
|
||||
spread_row_ptr->type_vector =
|
||||
(int *) PHRQ_realloc (spread_row_ptr->type_vector,
|
||||
(size_t) spread_row_ptr->count * sizeof (int));
|
||||
if (spread_row_ptr->type_vector == NULL)
|
||||
malloc_error ();
|
||||
*/
|
||||
}
|
||||
token = (char *) free_check_null(token);
|
||||
return (spread_row_ptr);
|
||||
}
|
||||
|
||||
@ -1228,32 +1107,26 @@ spread_row_free(struct spread_row *spread_row_ptr)
|
||||
(char *) free_check_null(spread_row_ptr->char_vector[i]);
|
||||
}
|
||||
|
||||
spread_row_ptr->char_vector =
|
||||
(char **) free_check_null(spread_row_ptr->char_vector);
|
||||
spread_row_ptr->d_vector =
|
||||
(LDBLE *) free_check_null(spread_row_ptr->d_vector);
|
||||
spread_row_ptr->type_vector =
|
||||
(int *) free_check_null(spread_row_ptr->type_vector);
|
||||
spread_row_ptr = (struct spread_row *) free_check_null(spread_row_ptr);
|
||||
spread_row_ptr->char_vector.clear();
|
||||
spread_row_ptr->d_vector.clear();
|
||||
spread_row_ptr->type_vector.clear();
|
||||
delete spread_row_ptr;
|
||||
return (OK);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
copy_token_tab(char *token_ptr, char **ptr, int *length)
|
||||
copy_token_tab(std::string& token, const char **cptr)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Copies from **ptr to *token_ptr until first tab is encountered.
|
||||
* Copies from **cptr to *token until first tab is encountered.
|
||||
*
|
||||
* Arguments:
|
||||
* *token_ptr output, place to store token
|
||||
*
|
||||
* **ptr input, character string to read token from
|
||||
* output, next position after token
|
||||
*
|
||||
* length output, length of token
|
||||
* *token output, place to store token
|
||||
*
|
||||
* **cptr input, character string to read token from
|
||||
* output, next position after token
|
||||
* Returns:
|
||||
* UPPER,
|
||||
* LOWER,
|
||||
@ -1267,8 +1140,9 @@ copy_token_tab(char *token_ptr, char **ptr, int *length)
|
||||
/*
|
||||
* Strip leading spaces
|
||||
*/
|
||||
while ((c = **ptr) == ' ')
|
||||
(*ptr)++;
|
||||
token.clear();
|
||||
while ((c = **cptr) == ' ')
|
||||
(*cptr)++;
|
||||
/*
|
||||
* Check what we have
|
||||
*/
|
||||
@ -1303,10 +1177,10 @@ copy_token_tab(char *token_ptr, char **ptr, int *length)
|
||||
i = 0;
|
||||
for (;;)
|
||||
{
|
||||
c = **ptr;
|
||||
c = **cptr;
|
||||
if (c == '\t')
|
||||
{
|
||||
(*ptr)++;
|
||||
(*cptr)++;
|
||||
break;
|
||||
}
|
||||
else if (c == '\0')
|
||||
@ -1315,13 +1189,11 @@ copy_token_tab(char *token_ptr, char **ptr, int *length)
|
||||
}
|
||||
else
|
||||
{
|
||||
token_ptr[i] = c;
|
||||
(*ptr)++;
|
||||
token.push_back(c);
|
||||
(*cptr)++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
token_ptr[i] = '\0';
|
||||
*length = i;
|
||||
/*
|
||||
* Strip trailing spaces
|
||||
*/
|
||||
@ -1330,17 +1202,12 @@ copy_token_tab(char *token_ptr, char **ptr, int *length)
|
||||
if (j != ' ')
|
||||
break;
|
||||
}
|
||||
if (j != i - 1)
|
||||
{
|
||||
token_ptr[j + 1] = '\0';
|
||||
*length = j + 1;
|
||||
}
|
||||
return (return_value);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
get_option_string(const char **opt_list, int count_opt_list, char **next_char)
|
||||
get_option_string(const char **opt_list, int count_opt_list, const char **next_char)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
@ -1348,7 +1215,7 @@ get_option_string(const char **opt_list, int count_opt_list, char **next_char)
|
||||
*/
|
||||
int j;
|
||||
int opt_l, opt;
|
||||
char *opt_ptr;
|
||||
const char *opt_ptr;
|
||||
char option[MAX_LENGTH];
|
||||
|
||||
opt_ptr = *next_char;
|
||||
|
||||
@ -238,9 +238,9 @@ step(LDBLE step_fraction)
|
||||
{
|
||||
int n;
|
||||
struct phase *p_ptr = phase_bsearch((it->first).c_str(), &n, FALSE);
|
||||
struct elt_list *e_ptr;
|
||||
const struct elt_list *e_ptr;
|
||||
LDBLE min = 1e10;
|
||||
for (e_ptr = p_ptr->next_elt; e_ptr->elt != NULL; e_ptr++)
|
||||
for (e_ptr = &p_ptr->next_elt[0]; e_ptr->elt != NULL; e_ptr++)
|
||||
{
|
||||
std::string e(e_ptr->elt->primary->elt->name);
|
||||
cxxNameDouble::iterator st = sys_tots.find(e.c_str());
|
||||
@ -266,9 +266,9 @@ step(LDBLE step_fraction)
|
||||
int n;
|
||||
struct phase *p_ptr = phase_bsearch(comp_ptr->Get_name().c_str(), &n, FALSE);
|
||||
|
||||
struct elt_list *e_ptr;
|
||||
const struct elt_list *e_ptr;
|
||||
LDBLE min = 1e10;
|
||||
for (e_ptr = p_ptr->next_elt; e_ptr->elt != NULL; e_ptr++)
|
||||
for (e_ptr = &p_ptr->next_elt[0]; e_ptr->elt != NULL; e_ptr++)
|
||||
{
|
||||
std::string e(e_ptr->elt->primary->elt->name);
|
||||
cxxNameDouble::iterator st = sys_tots.find(e.c_str());
|
||||
@ -663,7 +663,7 @@ add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr)
|
||||
int i;
|
||||
LDBLE amount_to_add, total;
|
||||
char token[MAX_LENGTH];
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
struct master *master_ptr;
|
||||
|
||||
if (check_pp_assemblage(pp_assemblage_ptr) == OK)
|
||||
@ -692,8 +692,8 @@ add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr)
|
||||
if (comp_ptr->Get_add_formula().size() > 0)
|
||||
{
|
||||
strcpy(token, comp_ptr->Get_add_formula().c_str());
|
||||
ptr = &(token[0]);
|
||||
get_elts_in_species(&ptr, 1.0);
|
||||
cptr = &(token[0]);
|
||||
get_elts_in_species(&cptr, 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -938,7 +938,7 @@ reaction_calc(cxxReaction *reaction_ptr)
|
||||
*/
|
||||
int return_value;
|
||||
LDBLE coef;
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
struct phase *phase_ptr;
|
||||
/*
|
||||
* Go through list and generate list of elements and
|
||||
@ -964,10 +964,8 @@ reaction_calc(cxxReaction *reaction_ptr)
|
||||
}
|
||||
else
|
||||
{
|
||||
char * token = string_duplicate(it->first.c_str());
|
||||
ptr = token;
|
||||
get_elts_in_species(&ptr, coef);
|
||||
free_check_null(token);
|
||||
cptr = it->first.c_str();
|
||||
get_elts_in_species(&cptr, coef);
|
||||
}
|
||||
}
|
||||
/*
|
||||
@ -1064,7 +1062,7 @@ add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr)
|
||||
int i, j, k;
|
||||
LDBLE amount_to_add, total;
|
||||
struct master *master_ptr;
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
|
||||
if (ss_assemblage_ptr == NULL)
|
||||
return (OK);
|
||||
@ -1089,11 +1087,9 @@ add_ss_assemblage(cxxSSassemblage *ss_assemblage_ptr)
|
||||
comp_ptr->Set_delta(0.0);
|
||||
if (comp_ptr->Get_moles() > 0.0)
|
||||
{
|
||||
char * token = string_duplicate(phase_ptr->formula);
|
||||
ptr = &(token[0]);
|
||||
cptr = phase_ptr->formula;
|
||||
count_elts = 0; // appt
|
||||
get_elts_in_species(&ptr, 1.0);
|
||||
free_check_null(token);
|
||||
get_elts_in_species(&cptr, 1.0);
|
||||
for (k = 0; k < count_elts; k++)
|
||||
{
|
||||
master_ptr = elt_list[k].elt->primary;
|
||||
@ -1270,7 +1266,7 @@ pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr)
|
||||
* Check for missing elements
|
||||
*/
|
||||
std::string token;
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
struct master *master_ptr;
|
||||
|
||||
if (check_pp_assemblage(pp_assemblage_ptr) == OK)
|
||||
@ -1293,8 +1289,8 @@ pp_assemblage_check(cxxPPassemblage *pp_assemblage_ptr)
|
||||
if (comp_ptr->Get_add_formula().size() > 0)
|
||||
{
|
||||
token = comp_ptr->Get_add_formula();
|
||||
ptr = &(token[0]);
|
||||
get_elts_in_species(&ptr, 1.0);
|
||||
cptr = &(token[0]);
|
||||
get_elts_in_species(&cptr, 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -117,9 +117,8 @@ get_all_components(void)
|
||||
* Buffer contains an entry for every primary master
|
||||
* species that can be used in the transport problem.
|
||||
*/
|
||||
t_buffer =
|
||||
(struct tally_buffer *) PHRQ_malloc((size_t) tally_count_component *
|
||||
sizeof(struct tally_buffer));
|
||||
t_buffer = (struct tally_buffer *) PHRQ_malloc(
|
||||
(size_t)tally_count_component * sizeof(struct tally_buffer));
|
||||
|
||||
// store alkalinity
|
||||
j = 0;
|
||||
@ -222,9 +221,9 @@ store_tally_table(LDBLE * l_array, int row_dim_in, int col_dim, LDBLE fill_facto
|
||||
/*
|
||||
* Add row for total moles of reactant
|
||||
*/
|
||||
for (i = 0; i < count_tally_table_columns; i++)
|
||||
for (size_t i = 0; i < count_tally_table_columns; i++)
|
||||
{
|
||||
l_array[i * row_dim + count_tally_table_rows] =
|
||||
l_array[i * (size_t)row_dim + count_tally_table_rows] =
|
||||
tally_table[i].moles / fill_factor;
|
||||
}
|
||||
return (OK);
|
||||
@ -244,8 +243,8 @@ get_tally_table_rows_columns(int *rows, int *columns)
|
||||
CONTINUE);
|
||||
return (ERROR);
|
||||
}
|
||||
*rows = count_tally_table_rows;
|
||||
*columns = count_tally_table_columns;
|
||||
*rows = (int)count_tally_table_rows;
|
||||
*columns = (int)count_tally_table_columns;
|
||||
return (OK);
|
||||
}
|
||||
|
||||
@ -317,14 +316,12 @@ free_tally_table(void)
|
||||
return (OK);
|
||||
for (i = 0; i < count_tally_table_columns; i++)
|
||||
{
|
||||
if (tally_table[i].formula != NULL)
|
||||
tally_table[i].formula =
|
||||
(struct elt_list *) free_check_null(tally_table[i].formula);
|
||||
if (tally_table[i].formula.size() != 0)
|
||||
tally_table[i].formula.clear();
|
||||
for (k = 0; k < 3; k++)
|
||||
{
|
||||
tally_table[i].total[k] =
|
||||
(struct tally_buffer *) free_check_null(tally_table[i].
|
||||
total[k]);
|
||||
tally_table[i].total[k] = (struct tally_buffer *) free_check_null(
|
||||
tally_table[i].total[k]);
|
||||
}
|
||||
}
|
||||
tally_table = (struct tally *) free_check_null(tally_table);
|
||||
@ -417,7 +414,7 @@ fill_tally_table(int *n_user, int index_conservative, int n_buffer)
|
||||
*/
|
||||
int found;
|
||||
LDBLE moles;
|
||||
//char *ptr;
|
||||
//const char* cptr;
|
||||
/*
|
||||
* Cycle through tally table columns
|
||||
*/
|
||||
@ -789,11 +786,12 @@ build_tally_table(void)
|
||||
* Also calculates a number greater than all user numbers and
|
||||
* stores in global variable first_user_number.
|
||||
*/
|
||||
int j, k, l, n, p, save_print_use;
|
||||
int j, k, l, p, save_print_use;
|
||||
size_t n;
|
||||
int count_tt_pure_phase, count_tt_ss_phase, count_tt_kinetics;
|
||||
struct phase *phase_ptr;
|
||||
char token[MAX_LENGTH];
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
/*
|
||||
* make list of all elements in all entitites
|
||||
* defines the number of rows in the table
|
||||
@ -907,8 +905,8 @@ build_tally_table(void)
|
||||
if (comp_ptr->Get_add_formula().size() > 0)
|
||||
{
|
||||
strcpy(token, comp_ptr->Get_add_formula().c_str());
|
||||
ptr = &(token[0]);
|
||||
get_elts_in_species(&ptr, 1.0);
|
||||
cptr = &(token[0]);
|
||||
get_elts_in_species(&cptr, 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -916,7 +914,7 @@ build_tally_table(void)
|
||||
add_elt_list(phase_ptr->next_elt, 1.0);
|
||||
}
|
||||
elt_list_combine();
|
||||
tally_table[n].formula = elt_list_save();
|
||||
tally_table[n].formula = elt_list_vsave();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -966,7 +964,7 @@ build_tally_table(void)
|
||||
strcpy(token, phase_ptr->formula);
|
||||
add_elt_list(phase_ptr->next_elt, 1.0);
|
||||
elt_list_combine();
|
||||
tally_table[n].formula = elt_list_save();
|
||||
tally_table[n].formula = elt_list_vsave();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1025,14 +1023,12 @@ build_tally_table(void)
|
||||
{
|
||||
std::string name = it->first;
|
||||
LDBLE coef = it->second;
|
||||
char * temp_name = string_duplicate(name.c_str());
|
||||
ptr = temp_name;
|
||||
get_elts_in_species(&ptr, 1.0 * coef);
|
||||
free_check_null(temp_name);
|
||||
cptr = name.c_str();
|
||||
get_elts_in_species(&cptr, 1.0 * coef);
|
||||
}
|
||||
}
|
||||
elt_list_combine();
|
||||
tally_table[n].formula = elt_list_save();
|
||||
tally_table[n].formula = elt_list_vsave();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1158,7 +1154,7 @@ calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr)
|
||||
* Go through kinetic components and add positive amount of each reactant
|
||||
*/
|
||||
LDBLE coef;
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
struct phase *phase_ptr;
|
||||
/*
|
||||
* Go through list and generate list of elements and
|
||||
@ -1190,11 +1186,8 @@ calc_dummy_kinetic_reaction_tally(cxxKinetics *kinetics_ptr)
|
||||
cxxNameDouble::iterator it = kinetics_comp_ptr->Get_namecoef().begin();
|
||||
for ( ; it != kinetics_comp_ptr->Get_namecoef().end(); it++)
|
||||
{
|
||||
std::string name = it->first;
|
||||
char * temp_name = string_duplicate(name.c_str());
|
||||
ptr = temp_name;
|
||||
get_elts_in_species(&ptr, coef);
|
||||
free_check_null(temp_name);
|
||||
cptr = it->first.c_str();
|
||||
get_elts_in_species(&cptr, coef);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1213,15 +1206,13 @@ extend_tally_table(void)
|
||||
* increments number of columns
|
||||
*/
|
||||
tally_table = (struct tally *) PHRQ_realloc((void *) tally_table,
|
||||
((size_t)count_tally_table_columns + 1) * sizeof(struct tally));
|
||||
(count_tally_table_columns + 1) * sizeof(struct tally));
|
||||
if (tally_table == NULL)
|
||||
malloc_error();
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
tally_table[count_tally_table_columns].total[i] =
|
||||
(struct tally_buffer *)
|
||||
PHRQ_malloc((size_t) (count_tally_table_rows) *
|
||||
sizeof(struct tally_buffer));
|
||||
tally_table[count_tally_table_columns].total[i] = (struct tally_buffer *)
|
||||
PHRQ_malloc(count_tally_table_rows * sizeof(struct tally_buffer));
|
||||
if (tally_table[count_tally_table_columns].total[i] == NULL)
|
||||
malloc_error();
|
||||
for (j = 0; j < count_tally_table_rows; j++)
|
||||
@ -1236,7 +1227,6 @@ extend_tally_table(void)
|
||||
tally_table[count_tally_table_columns].type = UnKnown;
|
||||
tally_table[count_tally_table_columns].add_formula = NULL;
|
||||
tally_table[count_tally_table_columns].moles = 0.0;
|
||||
tally_table[count_tally_table_columns].formula = NULL;
|
||||
count_tally_table_columns++;
|
||||
return (OK);
|
||||
}
|
||||
|
||||
@ -455,7 +455,7 @@ check_species_input(void)
|
||||
return_value = OK;
|
||||
for (i = 0; i < (int)s.size(); i++)
|
||||
{
|
||||
if (s[i]->next_elt == NULL)
|
||||
if (s[i]->next_elt.size() == 0)
|
||||
{
|
||||
input_error++;
|
||||
return_value = ERROR;
|
||||
@ -464,7 +464,7 @@ check_species_input(void)
|
||||
s[i]->name);
|
||||
error_msg(error_string, CONTINUE);
|
||||
}
|
||||
if (s[i]->rxn == NULL)
|
||||
if (s[i]->rxn.token.size() == 0)
|
||||
{
|
||||
input_error++;
|
||||
return_value = ERROR;
|
||||
@ -475,8 +475,8 @@ check_species_input(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
select_log_k_expression(s[i]->logk, s[i]->rxn->logk);
|
||||
add_other_logk(s[i]->rxn->logk, s[i]->add_logk);
|
||||
select_log_k_expression(s[i]->logk, s[i]->rxn.logk);
|
||||
add_other_logk(s[i]->rxn.logk, s[i]->add_logk);
|
||||
}
|
||||
}
|
||||
return (return_value);
|
||||
@ -569,7 +569,7 @@ add_other_logk(LDBLE * source_k, std::vector<struct name_coef> &add_logk)
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
"Could not find named temperature expression, %s\n",
|
||||
token);
|
||||
token.c_str());
|
||||
error_msg(error_string, CONTINUE);
|
||||
return (ERROR);
|
||||
}
|
||||
@ -634,7 +634,7 @@ add_logks(struct logk *logk_ptr, int repeats)
|
||||
input_error++;
|
||||
error_string = sformatf(
|
||||
"Could not find named temperature expression, %s\n",
|
||||
token);
|
||||
token.c_str());
|
||||
error_msg(error_string, CONTINUE);
|
||||
return (ERROR);
|
||||
}
|
||||
@ -663,19 +663,17 @@ coef_in_master(struct master * master_ptr)
|
||||
{
|
||||
int l;
|
||||
LDBLE coef;
|
||||
char *ptr;
|
||||
char elt_name[MAX_LENGTH];
|
||||
struct elt_list *next_elt;
|
||||
const char* cptr;
|
||||
std::string elt_name;
|
||||
const struct elt_list *next_elt;
|
||||
|
||||
coef = 0.0;
|
||||
char * temp_name = string_duplicate(master_ptr->elt->name);
|
||||
ptr = temp_name;
|
||||
get_elt(&ptr, elt_name, &l);
|
||||
free_check_null(temp_name);
|
||||
for (next_elt = master_ptr->s->next_elt; next_elt->elt != NULL;
|
||||
cptr = master_ptr->elt->name;
|
||||
get_elt(&cptr, elt_name, &l);
|
||||
for (next_elt = &master_ptr->s->next_elt[0]; next_elt->elt != NULL;
|
||||
next_elt++)
|
||||
{
|
||||
if (strcmp(elt_name, next_elt->elt->name) == 0)
|
||||
if (strcmp(elt_name.c_str(), next_elt->elt->name) == 0)
|
||||
{
|
||||
coef = next_elt->coef;
|
||||
break;
|
||||
@ -734,7 +732,7 @@ rewrite_eqn_to_secondary(void)
|
||||
&& token_ptr->s->primary == NULL)
|
||||
{
|
||||
coef = token_ptr->coef;
|
||||
trxn_add(token_ptr->s->rxn, coef, TRUE);
|
||||
trxn_add(token_ptr->s->rxn, coef, true);
|
||||
repeat = TRUE;
|
||||
break;
|
||||
}
|
||||
@ -813,12 +811,12 @@ replace_solids_gases(void)
|
||||
output_msg(sformatf( "Reaction to add.\n"));
|
||||
rxn_print(phase_ptr->rxn);
|
||||
*/
|
||||
trxn_add_phase(phase_ptr->rxn, coef, FALSE);
|
||||
trxn_add_phase(phase_ptr->rxn, coef, false);
|
||||
|
||||
/* remove solid/gas from trxn list */
|
||||
trxn.token[i].name = phase_ptr->rxn->token[0].name;
|
||||
trxn.token[i].s = phase_ptr->rxn->token[0].s;
|
||||
trxn.token[i].coef = -coef * phase_ptr->rxn->token[0].coef;
|
||||
trxn.token[i].name = phase_ptr->rxn.token[0].name;
|
||||
trxn.token[i].s = phase_ptr->rxn.token[0].s;
|
||||
trxn.token[i].coef = -coef * phase_ptr->rxn.token[0].coef;
|
||||
repeat = TRUE;
|
||||
replaced = TRUE;
|
||||
/* debug
|
||||
@ -883,7 +881,7 @@ rewrite_eqn_to_primary(void)
|
||||
{
|
||||
if (trxn.token[j].s->primary == NULL)
|
||||
{
|
||||
trxn_add(trxn.token[j].s->rxn, trxn.token[j].coef, TRUE);
|
||||
trxn_add(trxn.token[j].s->rxn, trxn.token[j].coef, true);
|
||||
repeat = TRUE;
|
||||
break;
|
||||
}
|
||||
@ -1104,10 +1102,9 @@ tidy_inverse(void)
|
||||
int i, j, k, l;
|
||||
int count_in;
|
||||
LDBLE value;
|
||||
struct inv_elts *inv_elts;
|
||||
struct master *master_ptr;
|
||||
struct master *master_alk_ptr;
|
||||
struct elt_list *elt_list_ptr;
|
||||
const struct elt_list *elt_list_ptr;
|
||||
master_alk_ptr = master_bsearch("Alkalinity");
|
||||
for (i = 0; i < count_inverse; i++)
|
||||
{
|
||||
@ -1116,62 +1113,45 @@ tidy_inverse(void)
|
||||
/*
|
||||
* Set default uncertainties for all solutions, if necessary
|
||||
*/
|
||||
if (inverse[i].count_uncertainties < inverse[i].count_solns)
|
||||
if (inverse[i].uncertainties.size() < inverse[i].count_solns)
|
||||
{
|
||||
inverse[i].uncertainties =
|
||||
(LDBLE *) PHRQ_realloc(inverse[i].uncertainties,
|
||||
(size_t) inverse[i].count_solns *
|
||||
sizeof(LDBLE));
|
||||
if (inverse[i].uncertainties == NULL)
|
||||
malloc_error();
|
||||
for (j = inverse[i].count_uncertainties;
|
||||
j < inverse[i].count_solns; j++)
|
||||
size_t count = inverse[i].uncertainties.size();
|
||||
double value = (count > 0) ? inverse[i].uncertainties.back() : 0.05;
|
||||
inverse[i].uncertainties.resize(inverse[i].count_solns);
|
||||
for (size_t j = count; j < inverse[i].count_solns; j++)
|
||||
{
|
||||
inverse[i].uncertainties[j] =
|
||||
inverse[i].uncertainties[inverse[i].count_uncertainties -
|
||||
1];
|
||||
inverse[i].uncertainties[j] = value;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Set default ph uncertainties for all solutions, if necessary
|
||||
*/
|
||||
if (inverse[i].count_ph_uncertainties < inverse[i].count_solns)
|
||||
if (inverse[i].ph_uncertainties.size() < inverse[i].count_solns)
|
||||
{
|
||||
inverse[i].ph_uncertainties =
|
||||
(LDBLE *) PHRQ_realloc(inverse[i].ph_uncertainties,
|
||||
(size_t) inverse[i].count_solns *
|
||||
sizeof(LDBLE));
|
||||
if (inverse[i].ph_uncertainties == NULL)
|
||||
malloc_error();
|
||||
for (j = inverse[i].count_ph_uncertainties;
|
||||
j < inverse[i].count_solns; j++)
|
||||
size_t count = inverse[i].ph_uncertainties.size();
|
||||
double value = (count > 0) ? inverse[i].ph_uncertainties.back() : 0.05;
|
||||
inverse[i].ph_uncertainties.resize(inverse[i].count_solns);
|
||||
for (size_t j = count; j < inverse[i].count_solns; j++)
|
||||
{
|
||||
inverse[i].ph_uncertainties[j] =
|
||||
inverse[i].ph_uncertainties[inverse[i].
|
||||
count_ph_uncertainties - 1];
|
||||
inverse[i].ph_uncertainties[j] = value;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Set default force for all solutions
|
||||
*/
|
||||
if (inverse[i].count_force_solns < inverse[i].count_solns)
|
||||
if (inverse[i].force_solns.size() < inverse[i].count_solns)
|
||||
{
|
||||
inverse[i].force_solns =
|
||||
(int *) PHRQ_realloc(inverse[i].force_solns,
|
||||
(size_t) inverse[i].count_solns *
|
||||
sizeof(int));
|
||||
if (inverse[i].force_solns == NULL)
|
||||
malloc_error();
|
||||
for (j = inverse[i].count_force_solns; j < inverse[i].count_solns;
|
||||
j++)
|
||||
size_t count = inverse[i].force_solns.size();
|
||||
inverse[i].force_solns.resize(inverse[i].count_solns);
|
||||
for (size_t j = count; j < inverse[i].count_solns; j++)
|
||||
{
|
||||
inverse[i].force_solns[j] = FALSE;
|
||||
inverse[i].force_solns[j] = false;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Find master species for element, set uncertainties
|
||||
*/
|
||||
for (j = 0; j < inverse[i].count_elts; j++)
|
||||
for (j = 0; j < inverse[i].elts.size(); j++)
|
||||
{
|
||||
inverse[i].elts[j].master =
|
||||
master_bsearch_primary(inverse[i].elts[j].name);
|
||||
@ -1183,13 +1163,9 @@ tidy_inverse(void)
|
||||
error_msg(error_string, CONTINUE);
|
||||
continue;
|
||||
}
|
||||
inverse[i].elts[j].uncertainties =
|
||||
(LDBLE *) PHRQ_realloc(inverse[i].elts[j].uncertainties,
|
||||
(size_t) inverse[i].count_solns *
|
||||
sizeof(LDBLE));
|
||||
if (inverse[i].elts[j].uncertainties == NULL)
|
||||
malloc_error();
|
||||
if (inverse[i].elts[j].count_uncertainties == 0)
|
||||
size_t count_uncertainties = inverse[i].elts[j].uncertainties.size();
|
||||
inverse[i].elts[j].uncertainties.resize((size_t)inverse[i].count_solns);
|
||||
if (count_uncertainties == 0)
|
||||
{
|
||||
/* use default uncertainties for element */
|
||||
for (k = 0; k < inverse[i].count_solns; k++)
|
||||
@ -1198,15 +1174,11 @@ tidy_inverse(void)
|
||||
inverse[i].uncertainties[k];
|
||||
}
|
||||
}
|
||||
else if (inverse[i].elts[j].count_uncertainties <
|
||||
inverse[i].count_solns)
|
||||
else if (count_uncertainties < inverse[i].count_solns)
|
||||
{
|
||||
/* use input uncertainties, fill in any missing at end */
|
||||
value =
|
||||
inverse[i].elts[j].uncertainties[inverse[i].elts[j].
|
||||
count_uncertainties - 1];
|
||||
for (k = inverse[i].elts[j].count_uncertainties;
|
||||
k < inverse[i].count_solns; k++)
|
||||
value = inverse[i].elts[j].uncertainties[count_uncertainties - 1];
|
||||
for (size_t k = count_uncertainties; k < inverse[i].count_solns; k++)
|
||||
{
|
||||
inverse[i].elts[j].uncertainties[k] = value;
|
||||
}
|
||||
@ -1217,7 +1189,7 @@ tidy_inverse(void)
|
||||
*/
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
for (j = 0; j < inverse[i].count_phases; j++)
|
||||
for (j = 0; j < inverse[i].phases.size(); j++)
|
||||
{
|
||||
inverse[i].phases[j].phase =
|
||||
phase_bsearch(inverse[i].phases[j].name, &k, FALSE);
|
||||
@ -1232,9 +1204,9 @@ tidy_inverse(void)
|
||||
/*
|
||||
* Find isotope elements
|
||||
*/
|
||||
if (inverse[i].phases[j].count_isotopes > 0)
|
||||
if (inverse[i].phases[j].isotopes.size() > 0)
|
||||
{
|
||||
for (k = 0; k < inverse[i].phases[j].count_isotopes; k++)
|
||||
for (k = 0; k < inverse[i].phases[j].isotopes.size(); k++)
|
||||
{
|
||||
inverse[i].phases[j].isotopes[k].primary = NULL;
|
||||
inverse[i].phases[j].isotopes[k].master = NULL;
|
||||
@ -1264,7 +1236,7 @@ tidy_inverse(void)
|
||||
inverse[i].phases[j].isotopes[k].primary = master_ptr;
|
||||
inverse[i].phases[j].isotopes[k].master = master_ptr;
|
||||
/* find coefficient for element */
|
||||
for (elt_list_ptr = inverse[i].phases[j].phase->next_elt;
|
||||
for (elt_list_ptr = &inverse[i].phases[j].phase->next_elt[0];
|
||||
elt_list_ptr->elt != NULL; elt_list_ptr++)
|
||||
{
|
||||
if (elt_list_ptr->elt == master_ptr->elt)
|
||||
@ -1285,9 +1257,9 @@ tidy_inverse(void)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
qsort(inverse[i].phases[j].isotopes,
|
||||
(size_t) inverse[i].phases[j].count_isotopes,
|
||||
(size_t) sizeof(struct isotope), isotope_compare);
|
||||
qsort(&inverse[i].phases[j].isotopes[0],
|
||||
inverse[i].phases[j].isotopes.size(),
|
||||
sizeof(struct isotope), isotope_compare);
|
||||
}
|
||||
add_elt_list(inverse[i].phases[j].phase->next_elt, 1.0);
|
||||
|
||||
@ -1308,7 +1280,7 @@ tidy_inverse(void)
|
||||
elt_list[j].elt->master->in = TRUE;
|
||||
}
|
||||
/* Include all input elements */
|
||||
for (j = 0; j < inverse[i].count_elts; j++)
|
||||
for (j = 0; j < inverse[i].elts.size(); j++)
|
||||
{
|
||||
inverse[i].elts[j].master->in = TRUE;
|
||||
}
|
||||
@ -1364,11 +1336,8 @@ tidy_inverse(void)
|
||||
/*
|
||||
* Save list of master species in inv_elts structure
|
||||
*/
|
||||
inv_elts =
|
||||
(struct inv_elts *) PHRQ_malloc((size_t) (count_in) *
|
||||
sizeof(struct inv_elts));
|
||||
if (inv_elts == NULL)
|
||||
malloc_error();
|
||||
std::vector<struct inv_elts> inv_elts;
|
||||
inv_elts.resize(count_in);
|
||||
count_in = 0;
|
||||
for (j = 0; j < (int)master.size(); j++)
|
||||
{
|
||||
@ -1380,11 +1349,7 @@ tidy_inverse(void)
|
||||
/* set master */
|
||||
inv_elts[count_in].master = master[j];
|
||||
/* alloc uncertainties and set default */
|
||||
inv_elts[count_in].uncertainties =
|
||||
(LDBLE *) PHRQ_malloc((size_t) inverse[i].count_solns *
|
||||
sizeof(LDBLE));
|
||||
if (inv_elts[count_in].uncertainties == NULL)
|
||||
malloc_error();
|
||||
inv_elts[count_in].uncertainties.resize((size_t)inverse[i].count_solns);
|
||||
for (k = 0; k < inverse[i].count_solns; k++)
|
||||
{
|
||||
inv_elts[count_in].uncertainties[k] =
|
||||
@ -1405,7 +1370,7 @@ tidy_inverse(void)
|
||||
* copy in input uncertainties
|
||||
*/
|
||||
/* copy primary redox to all secondary redox */
|
||||
for (j = 0; j < inverse[i].count_elts; j++)
|
||||
for (j = 0; j < inverse[i].elts.size(); j++)
|
||||
{
|
||||
master_ptr = master_bsearch(inverse[i].elts[j].name);
|
||||
if (master_ptr == NULL)
|
||||
@ -1430,11 +1395,10 @@ tidy_inverse(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
inverse[i].elts[j].uncertainties =
|
||||
(LDBLE *) free_check_null(inverse[i].elts[j].uncertainties);
|
||||
inverse[i].elts[j].uncertainties.clear();
|
||||
}
|
||||
/* copy masters that are not primary redox */
|
||||
for (j = 0; j < inverse[i].count_elts; j++)
|
||||
for (j = 0; j < inverse[i].elts.size(); j++)
|
||||
{
|
||||
master_ptr = master_bsearch(inverse[i].elts[j].name);
|
||||
if (master_ptr == NULL)
|
||||
@ -1460,17 +1424,15 @@ tidy_inverse(void)
|
||||
break;
|
||||
}
|
||||
}
|
||||
inverse[i].elts[j].uncertainties =
|
||||
(LDBLE *) free_check_null(inverse[i].elts[j].uncertainties);
|
||||
inverse[i].elts[j].uncertainties.clear();
|
||||
}
|
||||
/*
|
||||
* replace elts in inverse struct
|
||||
*/
|
||||
inverse[i].elts =
|
||||
(struct inv_elts *) free_check_null(inverse[i].elts);
|
||||
inverse[i].elts.clear();
|
||||
inverse[i].elts = inv_elts;
|
||||
inverse[i].count_elts = count_in;
|
||||
for (j = 0; j < inverse[i].count_elts; j++)
|
||||
inverse[i].elts.resize(count_in);
|
||||
for (j = 0; j < inverse[i].elts.size(); j++)
|
||||
{
|
||||
/* debug
|
||||
output_msg(sformatf( "\t%d\t%s", j, inverse[i].elts[j].master->elt->name));
|
||||
@ -1496,10 +1458,10 @@ tidy_phases(void)
|
||||
*/
|
||||
for (i = 0; i < (int)phases.size(); i++)
|
||||
{
|
||||
select_log_k_expression(phases[i]->logk, phases[i]->rxn->logk);
|
||||
add_other_logk(phases[i]->rxn->logk, phases[i]->add_logk);
|
||||
phases[i]->rxn->token[0].name = phases[i]->name;
|
||||
phases[i]->rxn->token[0].s = NULL;
|
||||
select_log_k_expression(phases[i]->logk, phases[i]->rxn.logk);
|
||||
add_other_logk(phases[i]->rxn.logk, phases[i]->add_logk);
|
||||
phases[i]->rxn.token[0].name = phases[i]->name;
|
||||
phases[i]->rxn.token[0].s = NULL;
|
||||
}
|
||||
/*
|
||||
* Rewrite all phases to secondary species
|
||||
@ -1510,7 +1472,7 @@ tidy_phases(void)
|
||||
* Rewrite equation
|
||||
*/
|
||||
count_trxn = 0;
|
||||
trxn_add_phase(phases[i]->rxn, 1.0, FALSE);
|
||||
trxn_add_phase(phases[i]->rxn, 1.0, false);
|
||||
trxn.token[0].name = phases[i]->name;
|
||||
/* debug
|
||||
output_msg(sformatf( "%s PHASE.\n", phases[i]->name));
|
||||
@ -1518,18 +1480,10 @@ tidy_phases(void)
|
||||
*/
|
||||
replaced = replace_solids_gases();
|
||||
phases[i]->replaced = replaced;
|
||||
/* save rxn */
|
||||
/*
|
||||
rxn_free(phases[i]->rxn);
|
||||
phases[i]->rxn = rxn_alloc(count_trxn + 1);
|
||||
trxn_copy(phases[i]->rxn);
|
||||
*/
|
||||
/* save rxn_s */
|
||||
trxn_reverse_k();
|
||||
rewrite_eqn_to_secondary();
|
||||
trxn_reverse_k();
|
||||
rxn_free(phases[i]->rxn_s);
|
||||
phases[i]->rxn_s = rxn_alloc(count_trxn + 1);
|
||||
trxn_copy(phases[i]->rxn_s);
|
||||
/*
|
||||
* Check equation
|
||||
@ -1563,7 +1517,7 @@ tidy_pp_assemblage(void)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
LDBLE coef;
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
/*
|
||||
* Find pointers for pure phases
|
||||
*/
|
||||
@ -1608,20 +1562,18 @@ tidy_pp_assemblage(void)
|
||||
}
|
||||
if (it->second.Get_add_formula().size() > 0)
|
||||
{
|
||||
int first = count_elts;
|
||||
size_t first = count_elts;
|
||||
phase_ptr = phase_bsearch(it->second.Get_add_formula().c_str(), &k, FALSE);
|
||||
if (phase_ptr != NULL)
|
||||
{
|
||||
it->second.Set_add_formula(phase_ptr->formula);
|
||||
}
|
||||
{
|
||||
char * temp_add = string_duplicate(it->second.Get_add_formula().c_str());
|
||||
ptr = temp_add;
|
||||
get_elts_in_species(&ptr, coef);
|
||||
free_check_null(temp_add);
|
||||
cptr = it->second.Get_add_formula().c_str();
|
||||
get_elts_in_species(&cptr, coef);
|
||||
}
|
||||
/* check that all elements are in the database */
|
||||
for (int l = first; l < count_elts; l++)
|
||||
for (size_t l = first; l < count_elts; l++)
|
||||
{
|
||||
if (elt_list[l].elt->master == NULL)
|
||||
{
|
||||
@ -2270,14 +2222,6 @@ tidy_punch(void)
|
||||
}
|
||||
}
|
||||
fpunchf_heading("\n");
|
||||
//if (punch.user_punch == TRUE)
|
||||
//{
|
||||
// for (i = 0; i < user_punch_count_headings; i++)
|
||||
// {
|
||||
// fpunchf_heading(sformatf("%*s\t", l, user_punch_headings[i]));
|
||||
// }
|
||||
//}
|
||||
//fpunchf_heading("\n");
|
||||
|
||||
current_selected_output->Set_new_def(false);
|
||||
pr.punch = punch_save;
|
||||
@ -2299,7 +2243,8 @@ tidy_species(void)
|
||||
{
|
||||
int i, j;
|
||||
struct master *master_ptr;
|
||||
char c, *ptr;
|
||||
char c;
|
||||
const char* cptr;
|
||||
/*
|
||||
* Make sure species pointers are ok
|
||||
*/
|
||||
@ -2330,11 +2275,10 @@ tidy_species(void)
|
||||
}
|
||||
for (i = 0; i < (int)master.size(); i++)
|
||||
{
|
||||
char * temp_name = string_duplicate(master[i]->elt->name);
|
||||
ptr = temp_name;
|
||||
if (ptr[0] != '[')
|
||||
cptr = master[i]->elt->name;
|
||||
if (cptr[0] != '[')
|
||||
{
|
||||
while ((c = (int) *(++ptr)) != '\0')
|
||||
while ((c = (int) *(++cptr)) != '\0')
|
||||
{
|
||||
if (isupper((int) c))
|
||||
{
|
||||
@ -2347,7 +2291,6 @@ tidy_species(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
free_check_null(temp_name);
|
||||
/* store sequence number in master structure */
|
||||
master[i]->number = i;
|
||||
if (strcmp(master[i]->elt->name, "Alkalinity") != 0)
|
||||
@ -2386,16 +2329,14 @@ tidy_species(void)
|
||||
count_trxn = 0;
|
||||
if (master[i]->s->primary != NULL)
|
||||
{
|
||||
trxn_add(master[i]->s->rxn, 1.0, FALSE);
|
||||
trxn_add(master[i]->s->rxn, -1.0, TRUE);
|
||||
trxn_add(master[i]->s->rxn, 1.0, false);
|
||||
trxn_add(master[i]->s->rxn, -1.0, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
trxn_add(master[i]->s->rxn, 1.0, FALSE);
|
||||
trxn_add(master[i]->s->rxn, 1.0, false);
|
||||
rewrite_eqn_to_primary();
|
||||
}
|
||||
rxn_free(master[i]->rxn_primary);
|
||||
master[i]->rxn_primary = rxn_alloc(count_trxn + 1);
|
||||
trxn_copy(master[i]->rxn_primary);
|
||||
master[i]->coef = coef_in_master(master[i]);
|
||||
}
|
||||
@ -2407,16 +2348,16 @@ tidy_species(void)
|
||||
count_trxn = 0;
|
||||
if (s[i]->primary != NULL || s[i]->secondary != NULL)
|
||||
{
|
||||
trxn_add(s[i]->rxn, 1.0, FALSE);
|
||||
trxn_add(s[i]->rxn, -1.0, TRUE);
|
||||
trxn_add(s[i]->rxn, 1.0, false);
|
||||
trxn_add(s[i]->rxn, -1.0, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
trxn_add(s[i]->rxn, 1.0, FALSE);
|
||||
trxn_add(s[i]->rxn, 1.0, false);
|
||||
rewrite_eqn_to_secondary();
|
||||
}
|
||||
rxn_free(s[i]->rxn_s);
|
||||
s[i]->rxn_s = rxn_alloc(count_trxn + 1);
|
||||
//rxn_free(s[i].rxn_s);
|
||||
//s[i].rxn_s = rxn_alloc(count_trxn + 1);
|
||||
trxn_copy(s[i]->rxn_s);
|
||||
/* calculate alkalinity */
|
||||
s[i]->alk = calc_alk(s[i]->rxn_s);
|
||||
@ -2495,7 +2436,7 @@ tidy_species(void)
|
||||
*/
|
||||
for (i = 0; i < (int)s.size(); i++)
|
||||
{
|
||||
if (s[i]->next_secondary != NULL)
|
||||
if (s[i]->next_secondary.size() != 0)
|
||||
{
|
||||
s[i]->h = 0.0;
|
||||
s[i]->o = 0.0;
|
||||
@ -2557,11 +2498,11 @@ tidy_species(void)
|
||||
* Changed to be coefficient of exchanger
|
||||
*/
|
||||
LDBLE exchange_coef = 0.0;
|
||||
for (j = 1; s[i]->rxn_s->token[j].s != NULL; j++)
|
||||
for (j = 1; s[i]->rxn_s.token[j].s != NULL; j++)
|
||||
{
|
||||
if (s[i]->rxn_s->token[j].s->type == EX)
|
||||
if (s[i]->rxn_s.token[j].s->type == EX)
|
||||
{
|
||||
exchange_coef = s[i]->rxn_s->token[j].coef;
|
||||
exchange_coef = s[i]->rxn_s.token[j].coef;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -2581,11 +2522,11 @@ tidy_species(void)
|
||||
/*
|
||||
* Find coefficient of surface in rxn, store in equiv
|
||||
*/
|
||||
for (j = 1; s[i]->rxn_s->token[j].s != NULL; j++)
|
||||
for (j = 1; s[i]->rxn_s.token[j].s != NULL; j++)
|
||||
{
|
||||
if (s[i]->rxn_s->token[j].s->type == SURF)
|
||||
if (s[i]->rxn_s.token[j].s->type == SURF)
|
||||
{
|
||||
surface_coef = s[i]->rxn_s->token[j].coef;
|
||||
surface_coef = s[i]->rxn_s.token[j].coef;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -2630,7 +2571,7 @@ tidy_surface(void)
|
||||
* After all of data are read, fill in master species for surface comps
|
||||
* Sort surface
|
||||
*/
|
||||
char *ptr1;
|
||||
const char* cptr1;
|
||||
cxxSurface *surface_ptr;
|
||||
//std::map<int, cxxSurface>::iterator kit;
|
||||
//for (kit = Rxn_surface_map.begin(); kit != Rxn_surface_map.end(); kit++)
|
||||
@ -2714,10 +2655,8 @@ tidy_surface(void)
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
{
|
||||
char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str());
|
||||
ptr1 = temp_formula;
|
||||
get_elts_in_species(&ptr1, comp_ptr->Get_moles());
|
||||
free_check_null(temp_formula);
|
||||
cptr1 = comp_ptr->Get_formula().c_str();
|
||||
get_elts_in_species(&cptr1, comp_ptr->Get_moles());
|
||||
}
|
||||
{
|
||||
cxxNameDouble nd = elt_list_NameDouble();
|
||||
@ -2874,61 +2813,25 @@ species_rxn_to_trxn(struct species *s_ptr)
|
||||
* Copy reaction from reaction structure to
|
||||
* temp reaction structure.
|
||||
*/
|
||||
int i;
|
||||
|
||||
for (i = 0; s_ptr->rxn->token[i].s != NULL; i++)
|
||||
if (trxn.token.size() <= s_ptr->rxn.token.size())
|
||||
{
|
||||
trxn.token[i].name = s_ptr->rxn->token[i].s->name;
|
||||
trxn.token[i].z = s_ptr->rxn->token[i].s->z;
|
||||
trxn.token[i].s = s_ptr->rxn->token[i].s;
|
||||
trxn.token.resize(s_ptr->rxn.token.size());
|
||||
}
|
||||
count_trxn = 0;
|
||||
for (size_t i = 0; s_ptr->rxn.token[i].s != NULL; i++)
|
||||
{
|
||||
trxn.token[i].name = s_ptr->rxn.token[i].s->name;
|
||||
trxn.token[i].z = s_ptr->rxn.token[i].s->z;
|
||||
trxn.token[i].s = s_ptr->rxn.token[i].s;
|
||||
trxn.token[i].unknown = NULL;
|
||||
trxn.token[i].coef = s_ptr->rxn->token[i].coef;
|
||||
trxn.token[i].coef = s_ptr->rxn.token[i].coef;
|
||||
count_trxn = i + 1;
|
||||
if ((size_t)count_trxn + 1 > trxn.token.size())
|
||||
trxn.token.resize((size_t)count_trxn + 1);
|
||||
if (count_trxn + 1 > trxn.token.size())
|
||||
trxn.token.resize(count_trxn + 1);
|
||||
}
|
||||
return (OK);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
phase_rxn_to_trxn(struct phase *phase_ptr, struct reaction *rxn_ptr)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Copy reaction from reaction structure to
|
||||
* temp reaction structure.
|
||||
*/
|
||||
int i, l;
|
||||
char *ptr;
|
||||
char token[MAX_LENGTH];
|
||||
LDBLE l_z;
|
||||
|
||||
trxn.token[0].name = phase_ptr->formula;
|
||||
/* charge */
|
||||
char * temp_formula = string_duplicate(phase_ptr->formula);
|
||||
ptr = temp_formula;
|
||||
get_token(&ptr, token, &l_z, &l);
|
||||
free_check_null(temp_formula);
|
||||
trxn.token[0].z = l_z;
|
||||
trxn.token[0].s = NULL;
|
||||
trxn.token[0].unknown = NULL;
|
||||
/*trxn.token[0].coef = -1.0; */
|
||||
/* check for leading coefficient of 1.0 for phase did not work */
|
||||
trxn.token[0].coef = phase_ptr->rxn->token[0].coef;
|
||||
for (i = 1; rxn_ptr->token[i].s != NULL; i++)
|
||||
{
|
||||
trxn.token[i].name = rxn_ptr->token[i].s->name;
|
||||
trxn.token[i].z = rxn_ptr->token[i].s->z;
|
||||
trxn.token[i].s = NULL;
|
||||
trxn.token[i].unknown = NULL;
|
||||
trxn.token[i].coef = rxn_ptr->token[i].coef;
|
||||
count_trxn = i + 1;
|
||||
if ((size_t)count_trxn + 1 > trxn.token.size())
|
||||
trxn.token.resize((size_t)count_trxn + 1);
|
||||
}
|
||||
return (OK);
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
tidy_isotopes(void)
|
||||
@ -2940,7 +2843,7 @@ tidy_isotopes(void)
|
||||
LDBLE isotope_number;
|
||||
struct master *master_ptr, *primary_ptr;
|
||||
|
||||
int primary_number = 0;
|
||||
size_t primary_number = 0;
|
||||
primary_ptr = NULL;
|
||||
std::map<int, cxxSolution>::iterator it;
|
||||
for (it = Rxn_solution_map.begin(); it != Rxn_solution_map.end(); it++)
|
||||
@ -3026,7 +2929,7 @@ tidy_isotopes(void)
|
||||
/* for primary, fill in ratio for all secondary species */
|
||||
if (master_ptr->primary == TRUE && master_ptr->s->secondary != NULL)
|
||||
{
|
||||
for (int k = primary_number + 1; k < (int)master.size(); k++)
|
||||
for (size_t k = primary_number + 1; k < (int)master.size(); k++)
|
||||
{
|
||||
if (master[k]->elt->primary != primary_ptr)
|
||||
break;
|
||||
@ -3113,7 +3016,7 @@ tidy_kin_exchange(void)
|
||||
*/
|
||||
{
|
||||
cxxKinetics *kinetics_ptr;
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
LDBLE conc;
|
||||
|
||||
//std::map<int, cxxExchange>::iterator it = Rxn_exchange_map.begin();
|
||||
@ -3208,10 +3111,8 @@ tidy_kin_exchange(void)
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
{
|
||||
char * temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
|
||||
ptr = temp_formula;
|
||||
get_elts_in_species(&ptr, conc);
|
||||
free_check_null(temp_formula);
|
||||
cptr = comp_ref.Get_formula().c_str();
|
||||
get_elts_in_species(&cptr, conc);
|
||||
}
|
||||
comp_ref.Set_totals(elt_list_NameDouble());
|
||||
/*
|
||||
@ -3233,7 +3134,7 @@ update_kin_exchange(void)
|
||||
*/
|
||||
{
|
||||
cxxKinetics* kinetics_ptr;
|
||||
char* ptr;
|
||||
const char* cptr;
|
||||
LDBLE conc;
|
||||
|
||||
std::map<int, cxxExchange>::iterator it = Rxn_exchange_map.begin();
|
||||
@ -3321,10 +3222,8 @@ update_kin_exchange(void)
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
{
|
||||
char* temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
|
||||
ptr = temp_formula;
|
||||
get_elts_in_species(&ptr, 1.0);
|
||||
free_check_null(temp_formula);
|
||||
cptr = comp_ref.Get_formula().c_str();
|
||||
get_elts_in_species(&cptr, 1.0);
|
||||
}
|
||||
cxxNameDouble nd_formula = elt_list_NameDouble();
|
||||
double comp_coef = 0;
|
||||
@ -3344,10 +3243,8 @@ update_kin_exchange(void)
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
{
|
||||
char* temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
|
||||
ptr = temp_formula;
|
||||
get_elts_in_species(&ptr, conc);
|
||||
free_check_null(temp_formula);
|
||||
cptr = comp_ref.Get_formula().c_str();
|
||||
get_elts_in_species(&cptr, conc);
|
||||
}
|
||||
comp_ref.Set_totals(elt_list_NameDouble());
|
||||
}
|
||||
@ -3365,7 +3262,7 @@ tidy_min_exchange(void)
|
||||
*/
|
||||
{
|
||||
int n, jj;
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
LDBLE conc;
|
||||
|
||||
//std::map<int, cxxExchange>::iterator it = Rxn_exchange_map.begin();
|
||||
@ -3460,10 +3357,8 @@ tidy_min_exchange(void)
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
{
|
||||
char * temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
|
||||
ptr = temp_formula;
|
||||
get_elts_in_species(&ptr, conc);
|
||||
free_check_null(temp_formula);
|
||||
cptr = comp_ref.Get_formula().c_str();
|
||||
get_elts_in_species(&cptr, conc);
|
||||
}
|
||||
comp_ref.Set_totals(elt_list_NameDouble());
|
||||
/*
|
||||
@ -3472,19 +3367,15 @@ tidy_min_exchange(void)
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
{
|
||||
char * temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
|
||||
ptr = temp_formula;
|
||||
get_elts_in_species(&ptr, -comp_ref.Get_phase_proportion());
|
||||
free_check_null(temp_formula);
|
||||
cptr = comp_ref.Get_formula().c_str();
|
||||
get_elts_in_species(&cptr, -comp_ref.Get_phase_proportion());
|
||||
}
|
||||
int l;
|
||||
struct phase *phase_ptr = phase_bsearch(jit->first.c_str(), &l, FALSE);
|
||||
if (phase_ptr != NULL)
|
||||
{
|
||||
char * temp_formula = string_duplicate(phase_ptr->formula);
|
||||
ptr = temp_formula;
|
||||
get_elts_in_species(&ptr, 1.0);
|
||||
free_check_null(temp_formula);
|
||||
cptr = phase_ptr->formula;
|
||||
get_elts_in_species(&cptr, 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3527,7 +3418,7 @@ update_min_exchange(void)
|
||||
*/
|
||||
{
|
||||
int n, jj;
|
||||
char* ptr;
|
||||
const char* cptr;
|
||||
LDBLE conc;
|
||||
|
||||
std::map<int, cxxExchange>::iterator it = Rxn_exchange_map.begin();
|
||||
@ -3615,10 +3506,8 @@ update_min_exchange(void)
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
{
|
||||
char* temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
|
||||
ptr = temp_formula;
|
||||
get_elts_in_species(&ptr, 1.0);
|
||||
free_check_null(temp_formula);
|
||||
cptr = comp_ref.Get_formula().c_str();
|
||||
get_elts_in_species(&cptr, 1.0);
|
||||
}
|
||||
cxxNameDouble nd_formula = elt_list_NameDouble();
|
||||
double comp_coef = 0;
|
||||
@ -3638,10 +3527,8 @@ update_min_exchange(void)
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
{
|
||||
char* temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
|
||||
ptr = temp_formula;
|
||||
get_elts_in_species(&ptr, conc);
|
||||
free_check_null(temp_formula);
|
||||
cptr = comp_ref.Get_formula().c_str();
|
||||
get_elts_in_species(&cptr, conc);
|
||||
}
|
||||
comp_ref.Set_totals(elt_list_NameDouble());
|
||||
/*
|
||||
@ -3650,19 +3537,15 @@ update_min_exchange(void)
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
{
|
||||
char* temp_formula = string_duplicate(comp_ref.Get_formula().c_str());
|
||||
ptr = temp_formula;
|
||||
get_elts_in_species(&ptr, -comp_ref.Get_phase_proportion());
|
||||
free_check_null(temp_formula);
|
||||
cptr = comp_ref.Get_formula().c_str();
|
||||
get_elts_in_species(&cptr, -comp_ref.Get_phase_proportion());
|
||||
}
|
||||
int l;
|
||||
struct phase* phase_ptr = phase_bsearch(jit->first.c_str(), &l, FALSE);
|
||||
if (phase_ptr != NULL)
|
||||
{
|
||||
char* temp_formula = string_duplicate(phase_ptr->formula);
|
||||
ptr = temp_formula;
|
||||
get_elts_in_species(&ptr, 1.0);
|
||||
free_check_null(temp_formula);
|
||||
cptr = phase_ptr->formula;
|
||||
get_elts_in_species(&cptr, 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3810,10 +3693,10 @@ tidy_min_surface(void)
|
||||
/* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */
|
||||
{
|
||||
char * temp_formula = string_duplicate(surface_comp_ptr->Get_formula().c_str());
|
||||
char *ptr = temp_formula;
|
||||
const char* cptr = temp_formula;
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
get_elts_in_species(&ptr, conc);
|
||||
get_elts_in_species(&cptr, conc);
|
||||
free_check_null(temp_formula);
|
||||
}
|
||||
{
|
||||
@ -3840,10 +3723,8 @@ tidy_min_surface(void)
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
{
|
||||
char * temp_formula = string_duplicate(phase_ptr->formula);
|
||||
char * ptr = temp_formula;
|
||||
get_elts_in_species(&ptr, 1.0);
|
||||
free_check_null(temp_formula);
|
||||
const char* cptr = phase_ptr->formula;
|
||||
get_elts_in_species(&cptr, 1.0);
|
||||
}
|
||||
// Revise logic for surface related to mineral
|
||||
for (size_t jj = 0; jj < surface_ptr->Get_surface_comps().size(); jj++)
|
||||
@ -3851,10 +3732,8 @@ tidy_min_surface(void)
|
||||
cxxSurfaceComp *comp_jj_ptr = &(surface_ptr->Get_surface_comps()[jj]);
|
||||
// Use formula for all types of surfaces
|
||||
{
|
||||
char * temp_formula = string_duplicate(comp_jj_ptr->Get_formula().c_str());
|
||||
char *ptr = temp_formula;
|
||||
get_elts_in_species(&ptr,
|
||||
-comp_jj_ptr->Get_phase_proportion());
|
||||
const char* cptr = comp_jj_ptr->Get_formula().c_str();
|
||||
get_elts_in_species(&cptr, -comp_jj_ptr->Get_phase_proportion());
|
||||
|
||||
if (surface_ptr->Get_type() != cxxSurface::CD_MUSIC)
|
||||
{
|
||||
@ -3867,7 +3746,6 @@ tidy_min_surface(void)
|
||||
error_string = sformatf("Unknown element definition in SURFACE \n\t for surface related to equilibrium_phase: SURFACE %d.",
|
||||
surface_ptr->Get_n_user());
|
||||
error_msg(error_string);
|
||||
free_check_null(temp_formula);
|
||||
continue;
|
||||
}
|
||||
if (elt_ptr->master->s == NULL || elt_ptr->master->s->name == NULL)
|
||||
@ -3876,7 +3754,6 @@ tidy_min_surface(void)
|
||||
error_string = sformatf("Unknown master species definition in SURFACE \n\t for surface related to equilibrium_phase: SURFACE %d.",
|
||||
surface_ptr->Get_n_user());
|
||||
error_msg(error_string);
|
||||
free_check_null(temp_formula);
|
||||
continue;
|
||||
}
|
||||
//if (strcmp(elt_ptr->master->s->name, temp_formula) != 0)
|
||||
@ -3893,7 +3770,6 @@ tidy_min_surface(void)
|
||||
warning_msg(error_string);
|
||||
}
|
||||
}
|
||||
free_check_null(temp_formula);
|
||||
}
|
||||
}
|
||||
elt_list_combine();
|
||||
@ -4064,10 +3940,10 @@ update_min_surface(void)
|
||||
else /* need to generate from scratch */
|
||||
{
|
||||
char* temp_formula = string_duplicate(surface_comp_ptr->Get_formula().c_str());
|
||||
char* ptr = temp_formula;
|
||||
const char* cptr = temp_formula;
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
get_elts_in_species(&ptr, conc);
|
||||
get_elts_in_species(&cptr, conc);
|
||||
free_check_null(temp_formula);
|
||||
|
||||
cxxNameDouble nd = elt_list_NameDouble();
|
||||
@ -4097,8 +3973,8 @@ tidy_kin_surface(void)
|
||||
{
|
||||
cxxKinetics *kinetics_ptr;
|
||||
struct phase *phase_ptr;
|
||||
struct elt_list *elt_list_kinetics;
|
||||
int count_elts_kinetics;
|
||||
std::vector<struct elt_list> elt_list_kinetics;
|
||||
size_t count_elts_kinetics;
|
||||
|
||||
//std::map<int, cxxSurface>::iterator it;
|
||||
//for (it = Rxn_surface_map.begin(); it != Rxn_surface_map.end(); it++)
|
||||
@ -4196,12 +4072,10 @@ tidy_kin_surface(void)
|
||||
|
||||
/* if (conc < MIN_RELATED_SURFACE) conc = 0.0; */
|
||||
{
|
||||
char * temp_formula = string_duplicate(comp_ptr->Get_formula().c_str());
|
||||
char *ptr = temp_formula;
|
||||
const char* cptr = comp_ptr->Get_formula().c_str();
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
get_elts_in_species(&ptr, conc);
|
||||
free_check_null(temp_formula);
|
||||
get_elts_in_species(&cptr, conc);
|
||||
}
|
||||
{
|
||||
if (surface_ptr->Get_new_def())
|
||||
@ -4258,10 +4132,8 @@ tidy_kin_surface(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
char * temp_name = string_duplicate(name.c_str());
|
||||
char * ptr = temp_name;
|
||||
get_elts_in_species(&ptr, coef);
|
||||
free_check_null(temp_name);
|
||||
const char* cptr = name.c_str();
|
||||
get_elts_in_species(&cptr, coef);
|
||||
}
|
||||
}
|
||||
/* save kinetics formula */
|
||||
@ -4269,7 +4141,7 @@ tidy_kin_surface(void)
|
||||
{
|
||||
elt_list_combine();
|
||||
}
|
||||
elt_list_kinetics = elt_list_save();
|
||||
elt_list_kinetics = elt_list_vsave();
|
||||
count_elts_kinetics = count_elts;
|
||||
|
||||
/* get surface formulas */
|
||||
@ -4286,10 +4158,8 @@ tidy_kin_surface(void)
|
||||
(comp_ptr->Get_rate_name().c_str(),
|
||||
kin_comp_ptr->Get_rate_name().c_str()) == 0)
|
||||
{
|
||||
char * temp_formula = string_duplicate( comp_ptr->Get_formula().c_str());
|
||||
char *ptr = temp_formula;
|
||||
get_elts_in_species(&ptr, -1 * comp_ptr->Get_phase_proportion());
|
||||
free_check_null(temp_formula);
|
||||
const char* cptr = comp_ptr->Get_formula().c_str();
|
||||
get_elts_in_species(&cptr, -1 * comp_ptr->Get_phase_proportion());
|
||||
}
|
||||
}
|
||||
elt_list_combine();
|
||||
@ -4356,8 +4226,7 @@ tidy_kin_surface(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
elt_list_kinetics =
|
||||
(struct elt_list *) free_check_null(elt_list_kinetics);
|
||||
elt_list_kinetics.clear();
|
||||
}
|
||||
}
|
||||
return (OK);
|
||||
@ -4476,12 +4345,10 @@ update_kin_surface(void)
|
||||
}
|
||||
else /* need to generate from scratch */
|
||||
{
|
||||
char* temp_formula = string_duplicate(comp_ptr->Get_formula().c_str());
|
||||
char* ptr = temp_formula;
|
||||
const char* cptr = comp_ptr->Get_formula().c_str();
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
get_elts_in_species(&ptr, conc);
|
||||
free_check_null(temp_formula);
|
||||
get_elts_in_species(&cptr, conc);
|
||||
|
||||
cxxNameDouble nd = elt_list_NameDouble();
|
||||
comp_ptr->Set_totals(nd);
|
||||
@ -4530,8 +4397,8 @@ ss_prep(LDBLE t, cxxSS *ss_ptr, int print)
|
||||
cxxSScomp *comp1_ptr = &(ss_ptr->Get_ss_comps()[1]);
|
||||
struct phase *phase0_ptr = phase_bsearch(comp0_ptr->Get_name().c_str(), &k, FALSE);
|
||||
struct phase *phase1_ptr = phase_bsearch(comp1_ptr->Get_name().c_str(), &k, FALSE);
|
||||
kc = exp(k_calc(phase0_ptr->rxn->logk, t, REF_PRES_PASCAL) * LOG_10);
|
||||
kb = exp(k_calc(phase1_ptr->rxn->logk, t, REF_PRES_PASCAL) * LOG_10);
|
||||
kc = exp(k_calc(phase0_ptr->rxn.logk, t, REF_PRES_PASCAL) * LOG_10);
|
||||
kb = exp(k_calc(phase1_ptr->rxn.logk, t, REF_PRES_PASCAL) * LOG_10);
|
||||
crit_pt = fabs(a0) + fabs(a1);
|
||||
/*
|
||||
* Default, no miscibility or spinodal gaps
|
||||
@ -5150,9 +5017,9 @@ ss_calc_a0_a1(cxxSS *ss_ptr)
|
||||
error_msg(error_string, CONTINUE);
|
||||
return (ERROR);
|
||||
}
|
||||
l_kc = exp(k_calc(phase0_ptr->rxn->logk, ss_ptr->Get_tk(), REF_PRES_PASCAL) *
|
||||
l_kc = exp(k_calc(phase0_ptr->rxn.logk, ss_ptr->Get_tk(), REF_PRES_PASCAL) *
|
||||
LOG_10);
|
||||
l_kb = exp(k_calc(phase1_ptr->rxn->logk, ss_ptr->Get_tk(), REF_PRES_PASCAL) *
|
||||
l_kb = exp(k_calc(phase1_ptr->rxn.logk, ss_ptr->Get_tk(), REF_PRES_PASCAL) *
|
||||
LOG_10);
|
||||
|
||||
p = ss_ptr->Get_p();
|
||||
@ -5613,30 +5480,15 @@ reset_last_model(void)
|
||||
/*
|
||||
* Initialize model
|
||||
*/
|
||||
last_model.force_prep = TRUE;
|
||||
last_model.count_exchange = 0;
|
||||
last_model.exchange =
|
||||
(struct master **) free_check_null(last_model.exchange);
|
||||
last_model.count_gas_phase = 0;
|
||||
last_model.gas_phase_type = cxxGasPhase::GP_UNKNOWN;
|
||||
last_model.gas_phase =
|
||||
(struct phase **) free_check_null(last_model.gas_phase);
|
||||
last_model.count_ss_assemblage = 0;
|
||||
last_model.ss_assemblage =
|
||||
(const char **) free_check_null(last_model.ss_assemblage);
|
||||
last_model.count_pp_assemblage = 0;
|
||||
last_model.pp_assemblage =
|
||||
(struct phase **) free_check_null(last_model.pp_assemblage);
|
||||
last_model.add_formula =
|
||||
(const char **) free_check_null(last_model.add_formula);
|
||||
last_model.si = (LDBLE *) free_check_null(last_model.si);
|
||||
last_model.force_prep = true;
|
||||
last_model.gas_phase.clear();
|
||||
last_model.ss_assemblage.clear();
|
||||
last_model.pp_assemblage.clear();
|
||||
last_model.add_formula.clear();
|
||||
last_model.si.clear();
|
||||
last_model.dl_type = cxxSurface::NO_DL;
|
||||
last_model.count_surface_comp = 0;
|
||||
last_model.surface_comp =
|
||||
(const char **) free_check_null(last_model.surface_comp);
|
||||
last_model.count_surface_charge = 0;
|
||||
last_model.surface_charge =
|
||||
(const char **) free_check_null(last_model.surface_charge);
|
||||
last_model.surface_comp.clear();
|
||||
last_model.surface_charge.clear();
|
||||
return (OK);
|
||||
}
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
@ -191,7 +191,7 @@ transport(void)
|
||||
/*
|
||||
* Initialize temperature in stagnant cells ...
|
||||
*/
|
||||
for (n = 1; n <= stag_data->count_stag; n++)
|
||||
for (n = 1; n <= stag_data.count_stag; n++)
|
||||
{
|
||||
for (i = 1; i <= count_cells; i++)
|
||||
{
|
||||
@ -248,7 +248,7 @@ transport(void)
|
||||
warning_msg(error_string);
|
||||
}
|
||||
current_cells = (struct CURRENT_CELLS *) PHRQ_malloc(
|
||||
((size_t)count_cells + 1) * sizeof(struct CURRENT_CELLS));
|
||||
(count_cells + 1) * sizeof(struct CURRENT_CELLS));
|
||||
if (current_cells == NULL)
|
||||
malloc_error();
|
||||
for (int i = 0; i < count_cells + 1; i++)
|
||||
@ -280,7 +280,7 @@ transport(void)
|
||||
warning_msg(error_string);
|
||||
timest = 1;
|
||||
}
|
||||
//if (implicit && stag_data->count_stag > 1)
|
||||
//if (implicit && stag_data.count_stag > 1)
|
||||
//{
|
||||
// error_string = sformatf(
|
||||
// "Sorry, implicit diffusion can handle only 1 stagnant layer for now. Please remove -implicit true, or set -stagnant 1.");
|
||||
@ -289,7 +289,7 @@ transport(void)
|
||||
if (implicit && current_cells == NULL)
|
||||
{
|
||||
current_cells = (struct CURRENT_CELLS *) PHRQ_malloc(
|
||||
((size_t)count_cells + 1) * sizeof(struct CURRENT_CELLS));
|
||||
(count_cells + 1) * sizeof(struct CURRENT_CELLS));
|
||||
if (current_cells == NULL)
|
||||
malloc_error();
|
||||
for (int i = 0; i < count_cells + 1; i++)
|
||||
@ -333,7 +333,7 @@ transport(void)
|
||||
/*
|
||||
* Also stagnant cells
|
||||
*/
|
||||
for (n = 1; n <= stag_data->count_stag; n++)
|
||||
for (n = 1; n <= stag_data.count_stag; n++)
|
||||
{
|
||||
for (i = 1; i <= count_cells; i++)
|
||||
{
|
||||
@ -358,7 +358,7 @@ transport(void)
|
||||
*/
|
||||
if (multi_Dflag)
|
||||
diffc_tr = diffc_max;
|
||||
if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1))
|
||||
if ((stag_data.exch_f > 0) && (stag_data.count_stag == 1))
|
||||
{
|
||||
/* multi_D calc's are OK if all cells have the same amount of water */
|
||||
if (multi_Dflag == TRUE)
|
||||
@ -397,7 +397,7 @@ transport(void)
|
||||
/*
|
||||
* Set boundary conditions, transport direction
|
||||
*/
|
||||
last_model.force_prep = TRUE;
|
||||
last_model.force_prep = true;
|
||||
if ((ishift == 0) || (bcon_first == 1) || (bcon_last == 1))
|
||||
b_c = 1;
|
||||
else
|
||||
@ -421,12 +421,12 @@ transport(void)
|
||||
* structure stag_data.
|
||||
* MIX 'cell_no' in input file can be an alternative for the calculation here.
|
||||
*/
|
||||
if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1))
|
||||
if ((stag_data.exch_f > 0) && (stag_data.count_stag == 1))
|
||||
{
|
||||
b = stag_data->th_m / (stag_data->th_m + stag_data->th_im);
|
||||
f = exp(-stag_data->exch_f * stagkin_time / (b * stag_data->th_im));
|
||||
b = stag_data.th_m / (stag_data.th_m + stag_data.th_im);
|
||||
f = exp(-stag_data.exch_f * stagkin_time / (b * stag_data.th_im));
|
||||
mix_f_imm = b - b * f;
|
||||
mix_f_m = mix_f_imm * stag_data->th_im / stag_data->th_m;
|
||||
mix_f_m = mix_f_imm * stag_data.th_im / stag_data.th_m;
|
||||
for (j = 1; j <= count_cells; j++)
|
||||
{
|
||||
j_imm = j + (1 + count_cells);
|
||||
@ -470,11 +470,11 @@ transport(void)
|
||||
/*
|
||||
* Assumption: D_e used for calculating exch_f in input file equals diffc
|
||||
*/
|
||||
f = stag_data->exch_f * (heat_diffc - diffc) / diffc / tempr;
|
||||
f = exp(-f * stagkin_time / (b * stag_data->th_im));
|
||||
f = stag_data.exch_f * (heat_diffc - diffc) / diffc / tempr;
|
||||
f = exp(-f * stagkin_time / (b * stag_data.th_im));
|
||||
heat_mix_f_imm = b - b * f;
|
||||
heat_mix_f_m =
|
||||
heat_mix_f_imm * stag_data->th_im / stag_data->th_m;
|
||||
heat_mix_f_imm * stag_data.th_im / stag_data.th_m;
|
||||
}
|
||||
}
|
||||
/*
|
||||
@ -510,7 +510,7 @@ transport(void)
|
||||
/*
|
||||
* Also stagnant cells
|
||||
*/
|
||||
for (n = 1; n <= stag_data->count_stag; n++)
|
||||
for (n = 1; n <= stag_data.count_stag; n++)
|
||||
{
|
||||
for (i = 1; i <= count_cells; i++)
|
||||
{
|
||||
@ -568,7 +568,7 @@ transport(void)
|
||||
STOP);
|
||||
}
|
||||
if (implicit)
|
||||
diffuse_implicit(stagkin_time, stag_data->count_stag);
|
||||
diffuse_implicit(stagkin_time, stag_data.count_stag);
|
||||
else if (multi_Dflag)
|
||||
multi_D(stagkin_time, 1, FALSE);
|
||||
|
||||
@ -576,7 +576,7 @@ transport(void)
|
||||
{
|
||||
if (!dV_dcell && (i == 0 || i == count_cells + 1) && !implicit)
|
||||
{
|
||||
if (j == nmix && stag_data->count_stag == 0 &&
|
||||
if (j == nmix && stag_data.count_stag == 0 &&
|
||||
(cell_data[0].print || cell_data[0].punch ||
|
||||
cell_data[count_cells + 1].print || cell_data[count_cells + 1].punch))
|
||||
print_punch(i, false);
|
||||
@ -607,7 +607,7 @@ transport(void)
|
||||
fill_spec(i, 0);
|
||||
|
||||
/* punch and output file */
|
||||
if (ishift == 0 && j == nmix && (stag_data->count_stag == 0 || (implicit && stag_data->count_stag == 1)))
|
||||
if (ishift == 0 && j == nmix && (stag_data.count_stag == 0 || (implicit && stag_data.count_stag == 1)))
|
||||
print_punch(i, true);
|
||||
if (i > 1)
|
||||
Utilities::Rxn_copy(Rxn_solution_map, -2, i - 1);
|
||||
@ -622,7 +622,7 @@ transport(void)
|
||||
timest + ((double)j - 1) * stagkin_time;
|
||||
rate_sim_time = rate_sim_time_start + stagkin_time;
|
||||
|
||||
if (stag_data->count_stag > 0)
|
||||
if (stag_data.count_stag > 0)
|
||||
{
|
||||
if (ishift == 0 && j == nmix)
|
||||
punch_boolean = TRUE;
|
||||
@ -633,9 +633,9 @@ transport(void)
|
||||
mix_stag(i, stagkin_time, punch_boolean, step_fraction);
|
||||
}
|
||||
}
|
||||
if (ishift == 0 && j == nmix && stag_data->count_stag > 0)
|
||||
if (ishift == 0 && j == nmix && stag_data.count_stag > 0)
|
||||
{
|
||||
for (n = 1; n <= stag_data->count_stag; n++)
|
||||
for (n = 1; n <= stag_data.count_stag; n++)
|
||||
{
|
||||
for (i = 1; i <= count_cells; i++)
|
||||
{
|
||||
@ -759,21 +759,21 @@ transport(void)
|
||||
fill_spec(i, i - 1);
|
||||
if (overall_iterations > max_iter)
|
||||
max_iter = overall_iterations;
|
||||
if (nmix == 0 && stag_data->count_stag == 0)
|
||||
if (nmix == 0 && stag_data.count_stag == 0)
|
||||
print_punch(i, true);
|
||||
if (i == first_c && count_cells > 1)
|
||||
kin_time = kin_time_save;
|
||||
saver();
|
||||
|
||||
/* If nmix is zero, stagnant zone mixing after advective step ... */
|
||||
if ((nmix == 0) && (stag_data->count_stag > 0))
|
||||
if ((nmix == 0) && (stag_data.count_stag > 0))
|
||||
{
|
||||
mix_stag(i, stagkin_time, TRUE, step_fraction);
|
||||
}
|
||||
}
|
||||
if (nmix == 0 && stag_data->count_stag > 0)
|
||||
if (nmix == 0 && stag_data.count_stag > 0)
|
||||
{
|
||||
for (n = 1; n <= stag_data->count_stag; n++)
|
||||
for (n = 1; n <= stag_data.count_stag; n++)
|
||||
{
|
||||
for (i = 1; i <= count_cells; i++)
|
||||
{
|
||||
@ -831,7 +831,7 @@ transport(void)
|
||||
error_msg("Error in surface transport, stopping.", STOP);
|
||||
}
|
||||
if (implicit)
|
||||
diffuse_implicit(stagkin_time, stag_data->count_stag);
|
||||
diffuse_implicit(stagkin_time, stag_data.count_stag);
|
||||
else if (multi_Dflag)
|
||||
multi_D(stagkin_time, 1, FALSE);
|
||||
|
||||
@ -840,7 +840,7 @@ transport(void)
|
||||
{
|
||||
if (!dV_dcell && (i == 0 || i == count_cells + 1) && !implicit)
|
||||
{
|
||||
if (j == nmix && stag_data->count_stag == 0 &&
|
||||
if (j == nmix && stag_data.count_stag == 0 &&
|
||||
(cell_data[0].print || cell_data[0].punch ||
|
||||
cell_data[count_cells + 1].print || cell_data[count_cells + 1].punch))
|
||||
print_punch(i, false);
|
||||
@ -867,7 +867,7 @@ transport(void)
|
||||
}
|
||||
if (multi_Dflag == TRUE)
|
||||
fill_spec(i, 0);
|
||||
if (j == nmix && (stag_data->count_stag == 0 || (implicit && stag_data->count_stag == 1)))
|
||||
if (j == nmix && (stag_data.count_stag == 0 || (implicit && stag_data.count_stag == 1)))
|
||||
print_punch(i, true);
|
||||
if (i > 1)
|
||||
Utilities::Rxn_copy(Rxn_solution_map, -2, i - 1);
|
||||
@ -880,7 +880,7 @@ transport(void)
|
||||
timest + ((double)j - 1) * stagkin_time;
|
||||
rate_sim_time = rate_sim_time_start + stagkin_time;
|
||||
|
||||
if (stag_data->count_stag > 0)
|
||||
if (stag_data.count_stag > 0)
|
||||
{
|
||||
if (j == nmix)
|
||||
punch_boolean = TRUE;
|
||||
@ -891,9 +891,9 @@ transport(void)
|
||||
mix_stag(i, stagkin_time, punch_boolean, step_fraction);
|
||||
}
|
||||
}
|
||||
if (j == nmix && ((stag_data->count_stag > 0/* && !implicit) || (implicit && stag_data->count_stag == 1*/)))
|
||||
if (j == nmix && ((stag_data.count_stag > 0/* && !implicit) || (implicit && stag_data.count_stag == 1*/)))
|
||||
{
|
||||
for (n = 1; n <= stag_data->count_stag; n++)
|
||||
for (n = 1; n <= stag_data.count_stag; n++)
|
||||
{
|
||||
for (i = 1; i <= count_cells; i++)
|
||||
{
|
||||
@ -979,7 +979,7 @@ transport_cleanup(void)
|
||||
* free mix structures
|
||||
*/
|
||||
Dispersion_mix_map.clear();
|
||||
if ((stag_data->exch_f > 0) && (stag_data->count_stag == 1))
|
||||
if ((stag_data.exch_f > 0) && (stag_data.count_stag == 1))
|
||||
{
|
||||
Rxn_mix_map.clear();
|
||||
}
|
||||
@ -1014,7 +1014,7 @@ transport_cleanup(void)
|
||||
}
|
||||
if (implicit)
|
||||
{
|
||||
int l_stag = (stag_data->count_stag < 2 ? stag_data->count_stag : 0);
|
||||
int l_stag = (stag_data.count_stag < 2 ? stag_data.count_stag : 0);
|
||||
Ct2 = (LDBLE *)free_check_null(Ct2);
|
||||
l_tk_x2 = (LDBLE *)free_check_null(l_tk_x2);
|
||||
if (A)
|
||||
@ -1102,10 +1102,10 @@ init_mix(void)
|
||||
bool warning = false;
|
||||
int i, l_nmix;
|
||||
LDBLE *m, *m1;
|
||||
m = (LDBLE *)PHRQ_malloc(((size_t)count_cells + 1) * sizeof(LDBLE));
|
||||
m = (LDBLE *)PHRQ_malloc((count_cells + 1) * sizeof(LDBLE));
|
||||
if (m == NULL)
|
||||
malloc_error();
|
||||
m1 = (LDBLE *)PHRQ_malloc(((size_t)count_cells + 1) * sizeof(LDBLE));
|
||||
m1 = (LDBLE *)PHRQ_malloc((count_cells + 1) * sizeof(LDBLE));
|
||||
if (m1 == NULL)
|
||||
malloc_error();
|
||||
for (i = 0; i < count_cells + 1; i++)
|
||||
@ -1202,7 +1202,7 @@ init_mix(void)
|
||||
if (maxmix == 0)
|
||||
{
|
||||
l_nmix = 0;
|
||||
if (mcd_substeps > 1 && stag_data->count_stag > 0)
|
||||
if (mcd_substeps > 1 && stag_data.count_stag > 0)
|
||||
l_nmix = (int) ceil(mcd_substeps);
|
||||
}
|
||||
else if (implicit)
|
||||
@ -1393,7 +1393,7 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction)
|
||||
/*
|
||||
* Kinetics in transport cell is done while transporting
|
||||
*/
|
||||
for (n = 1; n <= stag_data->count_stag; n++)
|
||||
for (n = 1; n <= stag_data.count_stag; n++)
|
||||
{
|
||||
if (i == 0 || i == count_cells + 1)
|
||||
{
|
||||
@ -1424,7 +1424,7 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction)
|
||||
{
|
||||
if (n == 1)
|
||||
{
|
||||
if (heat_nmix > 0 && (!implicit || (implicit && stag_data->count_stag > 1)))
|
||||
if (heat_nmix > 0 && (!implicit || (implicit && stag_data.count_stag > 1)))
|
||||
{
|
||||
ptr_m = Utilities::Rxn_find(Rxn_solution_map, i);
|
||||
t_imm =
|
||||
@ -1454,7 +1454,7 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction)
|
||||
error_msg("Error in surface transport, stopping.",
|
||||
STOP);
|
||||
}
|
||||
if (!implicit || (implicit && stag_data->count_stag > 1))
|
||||
if (!implicit || (implicit && stag_data.count_stag > 1))
|
||||
{
|
||||
if (multi_Dflag == TRUE)
|
||||
multi_D(1.0, i, 2);
|
||||
@ -1484,7 +1484,7 @@ mix_stag(int i, LDBLE kin_time, int l_punch, LDBLE step_fraction)
|
||||
|
||||
if (done_mixing) // after all mixing is done, the temporal solution becomes the original for the next timestep
|
||||
{
|
||||
for (n = 1; n <= stag_data->count_stag; n++)
|
||||
for (n = 1; n <= stag_data.count_stag; n++)
|
||||
{
|
||||
k = i + 1 + n * count_cells;
|
||||
if (Utilities::Rxn_find(Rxn_solution_map, k) != 0)
|
||||
@ -1533,7 +1533,7 @@ init_heat_mix(int l_nmix)
|
||||
{
|
||||
if (fabs(Utilities::Rxn_find(Rxn_solution_map, count_cells + 1)->Get_tc() - t0) > 1.0)
|
||||
l_heat_nmix = 1;
|
||||
for (n = 1; n <= stag_data->count_stag; n++)
|
||||
for (n = 1; n <= stag_data.count_stag; n++)
|
||||
{
|
||||
for (i = 1; i < count_cells; i++)
|
||||
{
|
||||
@ -1554,15 +1554,15 @@ init_heat_mix(int l_nmix)
|
||||
/*
|
||||
* Initialize arrays...
|
||||
*/
|
||||
heat_mix_array = (LDBLE *)PHRQ_malloc(((size_t)count_cells + 2) * sizeof(LDBLE));
|
||||
heat_mix_array = (LDBLE *)PHRQ_malloc((count_cells + 2) * sizeof(LDBLE));
|
||||
if (heat_mix_array == NULL)
|
||||
malloc_error();
|
||||
|
||||
temp1 = (LDBLE *)PHRQ_malloc(((size_t)count_cells + 2) * sizeof(LDBLE));
|
||||
temp1 = (LDBLE *)PHRQ_malloc((count_cells + 2) * sizeof(LDBLE));
|
||||
if (temp1 == NULL)
|
||||
malloc_error();
|
||||
|
||||
temp2 = (LDBLE *)PHRQ_malloc(((size_t)count_cells + 2) * sizeof(LDBLE));
|
||||
temp2 = (LDBLE *)PHRQ_malloc((count_cells + 2) * sizeof(LDBLE));
|
||||
if (temp2 == NULL)
|
||||
malloc_error();
|
||||
/*
|
||||
@ -1678,7 +1678,8 @@ set_initial_moles(int i)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
cxxKinetics *kinetics_ptr;
|
||||
char token[MAX_LENGTH], token1[MAX_LENGTH], *ptr;
|
||||
char token[MAX_LENGTH];
|
||||
const char* cptr;
|
||||
int j, k, l;
|
||||
/*
|
||||
* Pure phase assemblage
|
||||
@ -1763,12 +1764,15 @@ set_initial_moles(int i)
|
||||
count_elts = 0;
|
||||
paren_count = 0;
|
||||
strcpy(token, "X");
|
||||
ptr = token;
|
||||
get_elts_in_species(&ptr, 2e-10);
|
||||
ptr = token;
|
||||
cptr = token;
|
||||
get_elts_in_species(&cptr, 2e-10);
|
||||
cptr = token;
|
||||
LDBLE z;
|
||||
get_token(&ptr, token1, &z, &l);
|
||||
comp.Set_formula(token1);
|
||||
{
|
||||
std::string token1;
|
||||
get_token(&cptr, token1, &z, &l);
|
||||
comp.Set_formula(token1.c_str());
|
||||
}
|
||||
comp.Set_formula_z(z);
|
||||
comp.Set_totals(elt_list_NameDouble());
|
||||
comp.Set_charge_balance(0.0);
|
||||
@ -1949,9 +1953,9 @@ fill_spec(int l_cell_no, int ref_cell)
|
||||
}
|
||||
|
||||
/* find the aqueous species in the exchange reaction... */
|
||||
for (i2 = 0; (s_ptr->rxn->token[i2].s != NULL); i2++)
|
||||
for (i2 = 0; (s_ptr->rxn.token[i2].s != NULL); i2++)
|
||||
{
|
||||
if ((s_ptr2 = s_ptr->rxn->token[i2].s)->type == AQ)
|
||||
if ((s_ptr2 = s_ptr->rxn.token[i2].s)->type == AQ)
|
||||
break;
|
||||
}
|
||||
/* copy its name and Dw and charge... */
|
||||
@ -2022,7 +2026,7 @@ fill_spec(int l_cell_no, int ref_cell)
|
||||
if (i3 + count_spec + 1 > sol_D[l_cell_no].spec_size)
|
||||
{
|
||||
sol_D[l_cell_no].spec = (struct spec *) PHRQ_realloc(sol_D[l_cell_no].spec,
|
||||
((size_t)i3 + (size_t)count_spec + 1 + (size_t)size_xt) * sizeof(struct spec));
|
||||
((size_t)i3 + count_spec + 1 + (size_t)size_xt) * sizeof(struct spec));
|
||||
if (sol_D[l_cell_no].spec == NULL)
|
||||
malloc_error();
|
||||
sol_D[l_cell_no].spec_size = i3 + count_spec + 1 + size_xt;
|
||||
@ -2044,7 +2048,7 @@ fill_spec(int l_cell_no, int ref_cell)
|
||||
if (count_spec >= sol_D[l_cell_no].spec_size)
|
||||
{
|
||||
sol_D[l_cell_no].spec = (struct spec *) PHRQ_realloc(sol_D[l_cell_no].spec,
|
||||
((size_t)count_spec + (size_t)size_xt) * sizeof(struct spec));
|
||||
(count_spec + (size_t)size_xt) * sizeof(struct spec));
|
||||
if (sol_D[l_cell_no].spec == NULL)
|
||||
malloc_error();
|
||||
sol_D[l_cell_no].spec_size = count_spec + size_xt;
|
||||
@ -2216,20 +2220,20 @@ diffuse_implicit(LDBLE DDt, int stagnant)
|
||||
comp += 1;
|
||||
|
||||
if (Ct2 == NULL)
|
||||
Ct2 = (LDBLE *) PHRQ_malloc(((size_t)count_cells + 2 + (size_t)stagnant * (size_t)count_cells) * sizeof(LDBLE));
|
||||
Ct2 = (LDBLE *) PHRQ_malloc((count_cells + 2 + (size_t)stagnant * count_cells) * sizeof(LDBLE));
|
||||
if (Ct2 == NULL) malloc_error();
|
||||
if (l_tk_x2 == NULL)
|
||||
l_tk_x2 = (LDBLE *) PHRQ_malloc(((size_t)count_cells + 2 + (size_t)stagnant * (size_t)count_cells) * sizeof(LDBLE));
|
||||
l_tk_x2 = (LDBLE *) PHRQ_malloc((count_cells + 2 + (size_t)stagnant * count_cells) * sizeof(LDBLE));
|
||||
if (l_tk_x2 == NULL) malloc_error();
|
||||
|
||||
if (A == NULL)
|
||||
{
|
||||
A = (LDBLE **)PHRQ_malloc(((size_t)count_cells + 2 + (size_t)stagnant * (size_t)count_cells) * sizeof(LDBLE *));
|
||||
A = (LDBLE **)PHRQ_malloc((count_cells + 2 + (size_t)stagnant * count_cells) * sizeof(LDBLE *));
|
||||
if (A == NULL) malloc_error();
|
||||
for (i = 0; i < count_cells + 2 + stagnant * count_cells; i++)
|
||||
{
|
||||
if (stagnant)
|
||||
A[i] = (LDBLE *)PHRQ_calloc((2 * (size_t)count_cells + 2), sizeof(LDBLE));
|
||||
A[i] = (LDBLE *)PHRQ_calloc((2 * count_cells + 2), sizeof(LDBLE));
|
||||
else
|
||||
A[i] = (LDBLE *)PHRQ_malloc(3 * sizeof(LDBLE));
|
||||
if (A[i] == NULL) malloc_error();
|
||||
@ -2237,12 +2241,12 @@ diffuse_implicit(LDBLE DDt, int stagnant)
|
||||
}
|
||||
if (LU == NULL)
|
||||
{
|
||||
LU = (LDBLE **)PHRQ_malloc(((size_t)count_cells + 2 + (size_t)stagnant * (size_t)count_cells) * sizeof(LDBLE *));
|
||||
LU = (LDBLE **)PHRQ_malloc((count_cells + 2 + (size_t)stagnant * count_cells) * sizeof(LDBLE *));
|
||||
if (LU == NULL) malloc_error();
|
||||
for (i = 0; i < count_cells + 2 + stagnant * count_cells; i++)
|
||||
{
|
||||
if (stagnant)
|
||||
LU[i] = (LDBLE *)PHRQ_calloc((2 * (size_t)count_cells + 2), sizeof(LDBLE));
|
||||
LU[i] = (LDBLE *)PHRQ_calloc((2 * count_cells + 2), sizeof(LDBLE));
|
||||
else
|
||||
LU[i] = (LDBLE *)PHRQ_malloc(3 * sizeof(LDBLE));
|
||||
if (LU[i] == NULL) malloc_error();
|
||||
@ -2250,7 +2254,7 @@ diffuse_implicit(LDBLE DDt, int stagnant)
|
||||
}
|
||||
if (mixf == NULL)
|
||||
{
|
||||
mixf = (LDBLE **)PHRQ_malloc(((size_t)count_cells + 2) * sizeof(LDBLE *));
|
||||
mixf = (LDBLE **)PHRQ_malloc((count_cells + 2) * sizeof(LDBLE *));
|
||||
if (mixf == NULL) malloc_error();
|
||||
for (i = 0; i < count_cells + 2; i++)
|
||||
{
|
||||
@ -2261,7 +2265,7 @@ diffuse_implicit(LDBLE DDt, int stagnant)
|
||||
{
|
||||
if (mixf_stag == NULL)
|
||||
{
|
||||
mixf_stag = (LDBLE **)PHRQ_malloc(((size_t)count_cells + 2) * sizeof(LDBLE *));
|
||||
mixf_stag = (LDBLE **)PHRQ_malloc((count_cells + 2) * sizeof(LDBLE *));
|
||||
if (mixf_stag == NULL) malloc_error();
|
||||
for (i = 0; i < count_cells + 2; i++)
|
||||
{
|
||||
@ -2747,9 +2751,9 @@ diffuse_implicit(LDBLE DDt, int stagnant)
|
||||
break;
|
||||
}
|
||||
char * temp_name = string_duplicate(ct[1].J_ij[cp].name);
|
||||
char * ptr = temp_name;
|
||||
const char* cptr = temp_name;
|
||||
count_elts = 0;
|
||||
get_elts_in_species(&ptr, 1);
|
||||
get_elts_in_species(&cptr, 1);
|
||||
free_check_null(temp_name);
|
||||
for (int k = 0; k < count_elts; k++)
|
||||
{
|
||||
@ -2802,7 +2806,7 @@ diffuse_implicit(LDBLE DDt, int stagnant)
|
||||
((dV_dcell > 0) && ((cell_data[i].potV + dVc) > cell_data[count_cells + 1].potV)) ||
|
||||
((dV_dcell < 0) && ((cell_data[i].potV + dVc) < cell_data[count_cells + 1].potV)))
|
||||
{
|
||||
dVc = (cell_data[(size_t)count_cells + 1].potV - cell_data[i].potV) / ((double)count_cells + 1 - (double)i);
|
||||
dVc = (cell_data[count_cells + 1].potV - cell_data[i].potV) / ((double)count_cells + 1 - (double)i);
|
||||
}
|
||||
cell_data[i + 1].potV = cell_data[i].potV + dVc;
|
||||
}
|
||||
@ -2845,12 +2849,12 @@ diffuse_implicit(LDBLE DDt, int stagnant)
|
||||
ct[i].m_s = (struct M_S *) free_check_null(ct[i].m_s);
|
||||
if (ct[i].m_s == NULL)
|
||||
{
|
||||
ct[i].m_s = (struct M_S *) PHRQ_malloc(((size_t)count_m_s + 5) * sizeof(struct M_S));
|
||||
ct[i].m_s = (struct M_S *) PHRQ_malloc((count_m_s + 5) * sizeof(struct M_S));
|
||||
ct[i].m_s_size = count_m_s + 5;
|
||||
}
|
||||
else if (count_m_s > ct[i].m_s_size)
|
||||
{
|
||||
ct[i].m_s = (struct M_S *) PHRQ_realloc(ct[i].m_s, ((size_t)count_m_s + 5) * sizeof(struct M_S));
|
||||
ct[i].m_s = (struct M_S *) PHRQ_realloc(ct[i].m_s, (count_m_s + 5) * sizeof(struct M_S));
|
||||
ct[i].m_s_size = count_m_s + 5;
|
||||
}
|
||||
if (ct[i].m_s == NULL)
|
||||
@ -3268,7 +3272,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant)
|
||||
|
||||
for (int f_c = 0; f_c <= loop_f_c; f_c++)
|
||||
{
|
||||
for (n = 0; n <= (stagnant ? stag_data->count_stag : 0); n++) // allow for stagnant cell mixing with higher cells in the layer
|
||||
for (n = 0; n <= (stagnant ? stag_data.count_stag : 0); n++) // allow for stagnant cell mixing with higher cells in the layer
|
||||
{
|
||||
icell = mobile_cell + 1 + n * count_cells;
|
||||
if (stagnant)
|
||||
@ -3589,15 +3593,15 @@ fill_m_s(struct J_ij *l_J_ij, int l_J_ij_count_spec, int icell, int stagnant)
|
||||
*/
|
||||
int j, k, l;
|
||||
LDBLE fraction;
|
||||
char *ptr;
|
||||
const char* cptr;
|
||||
|
||||
for (j = 0; j < l_J_ij_count_spec; j++)
|
||||
{
|
||||
{
|
||||
char * temp_name = string_duplicate(l_J_ij[j].name);
|
||||
ptr = temp_name;
|
||||
cptr = temp_name;
|
||||
count_elts = 0;
|
||||
get_elts_in_species(&ptr, 1);
|
||||
get_elts_in_species(&cptr, 1);
|
||||
free_check_null(temp_name);
|
||||
}
|
||||
if (implicit && stagnant < 2)
|
||||
@ -5111,7 +5115,7 @@ Step (from cell 1 to count_cells + 1):
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (i >= 0 && i <= 1 + count_cells * (1 + stag_data->count_stag))
|
||||
if (i >= 0 && i <= 1 + count_cells * (1 + stag_data.count_stag))
|
||||
{
|
||||
surface_ptr1 = Utilities::Rxn_find(Rxn_surface_map, i);
|
||||
if (surface_ptr1 != NULL)
|
||||
@ -5439,7 +5443,7 @@ diff_stag_surf(int mobile_cell)
|
||||
cxxSurface *surface_n2_ptr;
|
||||
std::map<int, cxxSurface> Rxn_temp_surface_map;
|
||||
|
||||
for (ns = 0; ns < stag_data->count_stag; ns++)
|
||||
for (ns = 0; ns < stag_data.count_stag; ns++)
|
||||
{
|
||||
|
||||
i1 = mobile_cell + 1 + ns * count_cells;
|
||||
@ -5703,7 +5707,7 @@ diff_stag_surf(int mobile_cell)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (i >= 0 && i <= 1 + count_cells * (1 + stag_data->count_stag))
|
||||
if (i >= 0 && i <= 1 + count_cells * (1 + stag_data.count_stag))
|
||||
{
|
||||
surface_ptr1 = Utilities::Rxn_find(Rxn_surface_map, i);
|
||||
//if (surface_ptr1 != NULL)
|
||||
@ -6048,7 +6052,7 @@ calc_vm_Cl(void)
|
||||
{
|
||||
/* limit the Debye-Hueckel slope by b... */
|
||||
/* pitzer... */
|
||||
//s_ptr->rxn_x->logk[vm_tc] += s_ptr->z * s_ptr->z * 0.5 * DH_Av *
|
||||
//s_ptr->rxn_x.logk[vm_tc] += s_ptr->z * s_ptr->z * 0.5 * DH_Av *
|
||||
// log(1 + s_ptr->logk[b_Av] * sqrt(mu_x)) / s_ptr->logk[b_Av];
|
||||
/* extended DH... */
|
||||
V_Cl += s_ptr->z * s_ptr->z * 0.5 * DH_Av *
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user