mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-15 16:18:22 +01:00
Squashed 'src/' changes from 1a84cced..0da302ae
0da302ae Merge commit '2abb0b0bcd4bcae42f84ff001aba7f2ab6df2af7' 2abb0b0b Squashed 'phreeqcpp/' changes from 798f8f9..e4c4cf3 git-subtree-dir: src git-subtree-split: 0da302aedfffccd97d50d919d1c3e696859de899
This commit is contained in:
parent
231f8e3658
commit
0e2456f051
@ -1548,6 +1548,14 @@ listtokens(FILE * f, tokenrec * l_buf)
|
||||
case tokspecies_formula_:
|
||||
output_msg("SPECIES_FORMULA$");
|
||||
break;
|
||||
case tokphase_equation:
|
||||
case tokphase_equation_:
|
||||
output_msg("PHASE_EQUATION$");
|
||||
break;
|
||||
case tokspecies_equation:
|
||||
case tokspecies_equation_:
|
||||
output_msg("SPECIES_EQUATION$");
|
||||
break;
|
||||
case toksr:
|
||||
output_msg("SR");
|
||||
break;
|
||||
@ -4080,6 +4088,202 @@ factor(struct LOC_exec * LINK)
|
||||
}
|
||||
break;
|
||||
|
||||
case tokphase_equation:
|
||||
case tokphase_equation_:
|
||||
{
|
||||
require(toklp, LINK);
|
||||
std::string phase_name(stringfactor(STR1, LINK));
|
||||
varrec* elts_varrec = NULL, * coef_varrec = NULL;
|
||||
std::vector<std::pair<std::string, double> > stoichiometry;
|
||||
/*
|
||||
* Parse arguments
|
||||
*/
|
||||
require(tokcomma, LINK);
|
||||
|
||||
count_varrec = LINK->t->UU.vp;
|
||||
if (LINK->t->kind != tokvar || count_varrec->stringvar != 0)
|
||||
snerr(": Cannot find count variable");
|
||||
|
||||
/* return number of names of species */
|
||||
LINK->t = LINK->t->next;
|
||||
require(tokcomma, LINK);
|
||||
elts_varrec = LINK->t->UU.vp;
|
||||
if (LINK->t->kind != tokvar || elts_varrec->stringvar != 1)
|
||||
snerr(": Cannot find species string variable");
|
||||
|
||||
/* return coefficients of species */
|
||||
LINK->t = LINK->t->next;
|
||||
require(tokcomma, LINK);
|
||||
coef_varrec = LINK->t->UU.vp;
|
||||
if (LINK->t->kind != tokvar || coef_varrec->stringvar != 0)
|
||||
snerr(": Cannot find coefficient variable");
|
||||
LINK->t = LINK->t->next;
|
||||
|
||||
require(tokrp, LINK);
|
||||
|
||||
free_dim_stringvar(elts_varrec);
|
||||
PhreeqcPtr->free_check_null(coef_varrec->UU.U0.arr);
|
||||
coef_varrec->UU.U0.arr = NULL;
|
||||
/*
|
||||
* Call subroutine
|
||||
*/
|
||||
std::string eq = PhreeqcPtr->phase_equation(phase_name, stoichiometry);
|
||||
|
||||
// put type as return value
|
||||
n.stringval = true;
|
||||
n.UU.sval = PhreeqcPtr->string_duplicate(eq.c_str());
|
||||
|
||||
/*
|
||||
* fill in varrec structure
|
||||
*/
|
||||
|
||||
size_t count = stoichiometry.size();
|
||||
*count_varrec->UU.U0.val = (LDBLE)count;
|
||||
/*
|
||||
* malloc space
|
||||
*/
|
||||
elts_varrec->UU.U1.sarr = (char**)PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(char*));
|
||||
if (elts_varrec->UU.U1.sarr == NULL)
|
||||
{
|
||||
PhreeqcPtr->malloc_error();
|
||||
#if !defined(R_SO)
|
||||
exit(4);
|
||||
#endif
|
||||
}
|
||||
coef_varrec->UU.U0.arr = (LDBLE*)PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(LDBLE));
|
||||
if (coef_varrec->UU.U0.arr == NULL)
|
||||
{
|
||||
PhreeqcPtr->malloc_error();
|
||||
#if !defined(R_SO)
|
||||
exit(4);
|
||||
#endif
|
||||
}
|
||||
|
||||
// first position not used
|
||||
elts_varrec->UU.U1.sarr[0] = NULL;
|
||||
coef_varrec->UU.U0.arr[0] = 0;
|
||||
|
||||
// set dims for Basic array
|
||||
for (i = 0; i < maxdims; i++)
|
||||
{
|
||||
elts_varrec->dims[i] = 0;
|
||||
coef_varrec->dims[i] = 0;
|
||||
}
|
||||
// set dims for first dimension and number of dims
|
||||
elts_varrec->dims[0] = (long)(count + 1);
|
||||
coef_varrec->dims[0] = (long)(count + 1);
|
||||
elts_varrec->numdims = 1;
|
||||
coef_varrec->numdims = 1;
|
||||
|
||||
// fill in arrays
|
||||
i = 1;
|
||||
for (std::vector<std::pair<std::string, double > >::iterator it = stoichiometry.begin(); it != stoichiometry.end(); it++)
|
||||
{
|
||||
elts_varrec->UU.U1.sarr[i] = PhreeqcPtr->string_duplicate((it->first).c_str());
|
||||
coef_varrec->UU.U0.arr[i] = it->second;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case tokspecies_equation:
|
||||
case tokspecies_equation_:
|
||||
{
|
||||
require(toklp, LINK);
|
||||
std::string species_name(stringfactor(STR1, LINK));
|
||||
varrec* elts_varrec = NULL, * coef_varrec = NULL;
|
||||
std::vector<std::pair<std::string, double> > stoichiometry;
|
||||
/*
|
||||
* Parse arguments
|
||||
*/
|
||||
require(tokcomma, LINK);
|
||||
|
||||
count_varrec = LINK->t->UU.vp;
|
||||
if (LINK->t->kind != tokvar || count_varrec->stringvar != 0)
|
||||
snerr(": Cannot find count variable");
|
||||
|
||||
/* return number of names of species */
|
||||
LINK->t = LINK->t->next;
|
||||
require(tokcomma, LINK);
|
||||
elts_varrec = LINK->t->UU.vp;
|
||||
if (LINK->t->kind != tokvar || elts_varrec->stringvar != 1)
|
||||
snerr(": Cannot find species string variable");
|
||||
|
||||
/* return coefficients of species */
|
||||
LINK->t = LINK->t->next;
|
||||
require(tokcomma, LINK);
|
||||
coef_varrec = LINK->t->UU.vp;
|
||||
if (LINK->t->kind != tokvar || coef_varrec->stringvar != 0)
|
||||
snerr(": Cannot find coefficient variable");
|
||||
LINK->t = LINK->t->next;
|
||||
|
||||
require(tokrp, LINK);
|
||||
|
||||
free_dim_stringvar(elts_varrec);
|
||||
PhreeqcPtr->free_check_null(coef_varrec->UU.U0.arr);
|
||||
coef_varrec->UU.U0.arr = NULL;
|
||||
/*
|
||||
* Call subroutine
|
||||
*/
|
||||
std::string eq = PhreeqcPtr->species_equation(species_name, stoichiometry);
|
||||
|
||||
// put type as return value
|
||||
n.stringval = true;
|
||||
n.UU.sval = PhreeqcPtr->string_duplicate(eq.c_str());
|
||||
|
||||
/*
|
||||
* fill in varrec structure
|
||||
*/
|
||||
|
||||
size_t count = stoichiometry.size();
|
||||
*count_varrec->UU.U0.val = (LDBLE)count;
|
||||
/*
|
||||
* malloc space
|
||||
*/
|
||||
elts_varrec->UU.U1.sarr = (char**)PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(char*));
|
||||
if (elts_varrec->UU.U1.sarr == NULL)
|
||||
{
|
||||
PhreeqcPtr->malloc_error();
|
||||
#if !defined(R_SO)
|
||||
exit(4);
|
||||
#endif
|
||||
}
|
||||
coef_varrec->UU.U0.arr = (LDBLE*)PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(LDBLE));
|
||||
if (coef_varrec->UU.U0.arr == NULL)
|
||||
{
|
||||
PhreeqcPtr->malloc_error();
|
||||
#if !defined(R_SO)
|
||||
exit(4);
|
||||
#endif
|
||||
}
|
||||
|
||||
// first position not used
|
||||
elts_varrec->UU.U1.sarr[0] = NULL;
|
||||
coef_varrec->UU.U0.arr[0] = 0;
|
||||
|
||||
// set dims for Basic array
|
||||
for (i = 0; i < maxdims; i++)
|
||||
{
|
||||
elts_varrec->dims[i] = 0;
|
||||
coef_varrec->dims[i] = 0;
|
||||
}
|
||||
// set dims for first dimension and number of dims
|
||||
elts_varrec->dims[0] = (long)(count + 1);
|
||||
coef_varrec->dims[0] = (long)(count + 1);
|
||||
elts_varrec->numdims = 1;
|
||||
coef_varrec->numdims = 1;
|
||||
|
||||
// fill in arrays
|
||||
i = 1;
|
||||
for (std::vector<std::pair<std::string, double > >::iterator it = stoichiometry.begin(); it != stoichiometry.end(); it++)
|
||||
{
|
||||
elts_varrec->UU.U1.sarr[i] = PhreeqcPtr->string_duplicate((it->first).c_str());
|
||||
coef_varrec->UU.U0.arr[i] = it->second;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case toksr:
|
||||
{
|
||||
const char* str = stringfactor(STR1, LINK);
|
||||
@ -8088,6 +8292,10 @@ const std::map<const std::string, PBasic::BASIC_TOKEN>::value_type temp_tokens[]
|
||||
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("soln_vol", PBasic::toksoln_vol),
|
||||
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("species_formula", PBasic::tokspecies_formula),
|
||||
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("species_formula$", PBasic::tokspecies_formula_),
|
||||
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("phase_equation", PBasic::tokphase_equation),
|
||||
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("phase_equation$", PBasic::tokphase_equation_),
|
||||
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("species_equation", PBasic::tokspecies_equation),
|
||||
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("species_equation$", PBasic::tokspecies_equation_),
|
||||
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("sr", PBasic::toksr),
|
||||
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("step_no", PBasic::tokstep_no),
|
||||
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("str_e$", PBasic::tokstr_e_),
|
||||
|
||||
@ -323,6 +323,10 @@ public:
|
||||
toksoln_vol,
|
||||
tokspecies_formula,
|
||||
tokspecies_formula_,
|
||||
tokphase_equation,
|
||||
tokphase_equation_,
|
||||
tokspecies_equation,
|
||||
tokspecies_equation_,
|
||||
toksr,
|
||||
tokstep_no,
|
||||
tokstr_e_,
|
||||
|
||||
@ -167,6 +167,8 @@ public:
|
||||
std::string kinetics_formula(std::string kinetics_name, cxxNameDouble& stoichiometry);
|
||||
std::string phase_formula(std::string phase_name, cxxNameDouble& stoichiometry);
|
||||
std::string species_formula(std::string phase_name, cxxNameDouble& stoichiometry);
|
||||
std::string phase_equation(std::string phase_name, std::vector<std::pair<std::string, double> >& stoichiometry);
|
||||
std::string species_equation(std::string species_name, std::vector<std::pair<std::string, double> >& stoichiometry);
|
||||
LDBLE list_ss(std::string ss_name, cxxNameDouble& composition);
|
||||
int system_total_elements(void);
|
||||
int system_total_si(void);
|
||||
|
||||
@ -3009,6 +3009,109 @@ species_formula(std::string phase_name, cxxNameDouble& stoichiometry)
|
||||
return (formula);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
std::string Phreeqc::
|
||||
phase_equation(std::string phase_name, std::vector<std::pair<std::string, double> >& stoichiometry)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Returns equation
|
||||
* Also returns arrays of species and stoichiometry in stoichiometry
|
||||
*/
|
||||
stoichiometry.clear();
|
||||
std::ostringstream eq, lhs, rhs;
|
||||
int j = -1;
|
||||
class phase* phase_ptr = phase_bsearch(phase_name.c_str(), &j, FALSE);
|
||||
bool rhs_started = false;
|
||||
bool lhs_started = false;
|
||||
if (phase_ptr != NULL)
|
||||
{
|
||||
std::vector<rxn_token>::iterator it = phase_ptr->rxn.Get_tokens().begin();
|
||||
for (; it->name != NULL; it++)
|
||||
{
|
||||
if (!lhs_started)
|
||||
{
|
||||
std::pair<std::string, double> item(phase_ptr->formula, it->coef);
|
||||
stoichiometry.push_back(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::pair<std::string, double> item(it->name, it->coef);
|
||||
stoichiometry.push_back(item);
|
||||
}
|
||||
if (it->coef < 0.0)
|
||||
{
|
||||
if (lhs_started) lhs << "+ ";
|
||||
if (it->coef != -1.0)
|
||||
{
|
||||
lhs << -it->coef;
|
||||
}
|
||||
lhs << it->name << " ";
|
||||
lhs_started = true;
|
||||
}
|
||||
else if (it->coef > 0.0)
|
||||
{
|
||||
if (rhs_started) rhs << "+ ";
|
||||
if (it->coef != 1.0)
|
||||
{
|
||||
rhs << it->coef;
|
||||
}
|
||||
rhs << it->name << " ";
|
||||
rhs_started = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
eq << lhs.str() << "= " << rhs.str();
|
||||
return (eq.str());
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
std::string Phreeqc::
|
||||
species_equation(std::string species_name, std::vector<std::pair<std::string, double> >& stoichiometry)
|
||||
/* ---------------------------------------------------------------------- */
|
||||
{
|
||||
/*
|
||||
* Returns equation
|
||||
* Also returns arrays of species and stoichiometry in stoichiometry
|
||||
*/
|
||||
stoichiometry.clear();
|
||||
std::ostringstream eq, lhs, rhs;;
|
||||
class species* s_ptr = s_search(species_name.c_str());
|
||||
bool rhs_started = false;
|
||||
bool lhs_started = false;
|
||||
if (s_ptr != NULL)
|
||||
{
|
||||
std::vector<rxn_token>::iterator it = s_ptr->rxn.Get_tokens().begin();
|
||||
for ( ; it->name != NULL; it++)
|
||||
{
|
||||
std::pair<std::string, double> item(it->name, it->coef);
|
||||
stoichiometry.push_back(item);
|
||||
if (it->coef > 0.0)
|
||||
{
|
||||
if (lhs_started) lhs << "+ ";
|
||||
if (it->coef != 1.0)
|
||||
{
|
||||
lhs << it->coef;
|
||||
}
|
||||
lhs << it->name << " ";
|
||||
lhs_started = true;
|
||||
}
|
||||
else if (it->coef < 0.0)
|
||||
{
|
||||
if (rhs_started) rhs << "+ ";
|
||||
if (it->coef != -1.0)
|
||||
{
|
||||
rhs << -it->coef;
|
||||
}
|
||||
rhs << it->name << " ";
|
||||
rhs_started = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
eq << lhs.str() << "= " << rhs.str();
|
||||
return (eq.str());
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int Phreeqc::
|
||||
system_total_elements(void)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user