Skip to content

Commit ed78899

Browse files
author
Darth Vader
committed
Merge commit '7edbbfa268111a072cefc7a50eb9780c0a9f6df3'
2 parents 1f34f40 + 7edbbfa commit ed78899

File tree

7 files changed

+320
-3
lines changed

7 files changed

+320
-3
lines changed

src/phast/PhreeqcRM/database/Amm.dat

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ N(+5) NO3- 0 NO3
4444
N(+3) NO2- 0 NO2
4545
N(0) N2 0 N
4646
#N(-3) NH4+ 0 NH4 14.0067
47-
Amm AmmH+ 0 AmmH 17.031
47+
Amm AmmH+ 0 Amm 17.031
4848
B H3BO3 0 B 10.81
4949
P PO4-3 2 P 30.9738
5050
F F- 0 F 18.9984

src/phast/PhreeqcRM/database/phreeqc.dat

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ N(+5) NO3- 0 N
4444
N(+3) NO2- 0 N
4545
N(0) N2 0 N
4646
N(-3) NH4+ 0 N 14.0067
47-
#Amm AmmH+ 0 AmmH 17.031
47+
#Amm AmmH+ 0 Amm 17.031
4848
B H3BO3 0 B 10.81
4949
P PO4-3 2 P 30.9738
5050
F F- 0 F 18.9984

src/phast/PhreeqcRM/database/phreeqc_rates.dat

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ N(+5) NO3- 0 N
4444
N(+3) NO2- 0 N
4545
N(0) N2 0 N
4646
N(-3) NH4+ 0 N 14.0067
47-
#Amm AmmH+ 0 AmmH 17.031
47+
#Amm AmmH+ 0 Amm 17.031
4848
B H3BO3 0 B 10.81
4949
P PO4-3 2 P 30.9738
5050
F F- 0 F 18.9984

src/phast/PhreeqcRM/src/IPhreeqcPhast/IPhreeqc/phreeqcpp/PBasic.cpp

+208
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,14 @@ listtokens(FILE * f, tokenrec * l_buf)
15481548
case tokspecies_formula_:
15491549
output_msg("SPECIES_FORMULA$");
15501550
break;
1551+
case tokphase_equation:
1552+
case tokphase_equation_:
1553+
output_msg("PHASE_EQUATION$");
1554+
break;
1555+
case tokspecies_equation:
1556+
case tokspecies_equation_:
1557+
output_msg("SPECIES_EQUATION$");
1558+
break;
15511559
case toksr:
15521560
output_msg("SR");
15531561
break;
@@ -4080,6 +4088,202 @@ factor(struct LOC_exec * LINK)
40804088
}
40814089
break;
40824090

4091+
case tokphase_equation:
4092+
case tokphase_equation_:
4093+
{
4094+
require(toklp, LINK);
4095+
std::string phase_name(stringfactor(STR1, LINK));
4096+
varrec* elts_varrec = NULL, * coef_varrec = NULL;
4097+
std::vector<std::pair<std::string, double> > stoichiometry;
4098+
/*
4099+
* Parse arguments
4100+
*/
4101+
require(tokcomma, LINK);
4102+
4103+
count_varrec = LINK->t->UU.vp;
4104+
if (LINK->t->kind != tokvar || count_varrec->stringvar != 0)
4105+
snerr(": Cannot find count variable");
4106+
4107+
/* return number of names of species */
4108+
LINK->t = LINK->t->next;
4109+
require(tokcomma, LINK);
4110+
elts_varrec = LINK->t->UU.vp;
4111+
if (LINK->t->kind != tokvar || elts_varrec->stringvar != 1)
4112+
snerr(": Cannot find species string variable");
4113+
4114+
/* return coefficients of species */
4115+
LINK->t = LINK->t->next;
4116+
require(tokcomma, LINK);
4117+
coef_varrec = LINK->t->UU.vp;
4118+
if (LINK->t->kind != tokvar || coef_varrec->stringvar != 0)
4119+
snerr(": Cannot find coefficient variable");
4120+
LINK->t = LINK->t->next;
4121+
4122+
require(tokrp, LINK);
4123+
4124+
free_dim_stringvar(elts_varrec);
4125+
PhreeqcPtr->free_check_null(coef_varrec->UU.U0.arr);
4126+
coef_varrec->UU.U0.arr = NULL;
4127+
/*
4128+
* Call subroutine
4129+
*/
4130+
std::string eq = PhreeqcPtr->phase_equation(phase_name, stoichiometry);
4131+
4132+
// put type as return value
4133+
n.stringval = true;
4134+
n.UU.sval = PhreeqcPtr->string_duplicate(eq.c_str());
4135+
4136+
/*
4137+
* fill in varrec structure
4138+
*/
4139+
4140+
size_t count = stoichiometry.size();
4141+
*count_varrec->UU.U0.val = (LDBLE)count;
4142+
/*
4143+
* malloc space
4144+
*/
4145+
elts_varrec->UU.U1.sarr = (char**)PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(char*));
4146+
if (elts_varrec->UU.U1.sarr == NULL)
4147+
{
4148+
PhreeqcPtr->malloc_error();
4149+
#if !defined(R_SO)
4150+
exit(4);
4151+
#endif
4152+
}
4153+
coef_varrec->UU.U0.arr = (LDBLE*)PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(LDBLE));
4154+
if (coef_varrec->UU.U0.arr == NULL)
4155+
{
4156+
PhreeqcPtr->malloc_error();
4157+
#if !defined(R_SO)
4158+
exit(4);
4159+
#endif
4160+
}
4161+
4162+
// first position not used
4163+
elts_varrec->UU.U1.sarr[0] = NULL;
4164+
coef_varrec->UU.U0.arr[0] = 0;
4165+
4166+
// set dims for Basic array
4167+
for (i = 0; i < maxdims; i++)
4168+
{
4169+
elts_varrec->dims[i] = 0;
4170+
coef_varrec->dims[i] = 0;
4171+
}
4172+
// set dims for first dimension and number of dims
4173+
elts_varrec->dims[0] = (long)(count + 1);
4174+
coef_varrec->dims[0] = (long)(count + 1);
4175+
elts_varrec->numdims = 1;
4176+
coef_varrec->numdims = 1;
4177+
4178+
// fill in arrays
4179+
i = 1;
4180+
for (std::vector<std::pair<std::string, double > >::iterator it = stoichiometry.begin(); it != stoichiometry.end(); it++)
4181+
{
4182+
elts_varrec->UU.U1.sarr[i] = PhreeqcPtr->string_duplicate((it->first).c_str());
4183+
coef_varrec->UU.U0.arr[i] = it->second;
4184+
i++;
4185+
}
4186+
}
4187+
break;
4188+
4189+
case tokspecies_equation:
4190+
case tokspecies_equation_:
4191+
{
4192+
require(toklp, LINK);
4193+
std::string species_name(stringfactor(STR1, LINK));
4194+
varrec* elts_varrec = NULL, * coef_varrec = NULL;
4195+
std::vector<std::pair<std::string, double> > stoichiometry;
4196+
/*
4197+
* Parse arguments
4198+
*/
4199+
require(tokcomma, LINK);
4200+
4201+
count_varrec = LINK->t->UU.vp;
4202+
if (LINK->t->kind != tokvar || count_varrec->stringvar != 0)
4203+
snerr(": Cannot find count variable");
4204+
4205+
/* return number of names of species */
4206+
LINK->t = LINK->t->next;
4207+
require(tokcomma, LINK);
4208+
elts_varrec = LINK->t->UU.vp;
4209+
if (LINK->t->kind != tokvar || elts_varrec->stringvar != 1)
4210+
snerr(": Cannot find species string variable");
4211+
4212+
/* return coefficients of species */
4213+
LINK->t = LINK->t->next;
4214+
require(tokcomma, LINK);
4215+
coef_varrec = LINK->t->UU.vp;
4216+
if (LINK->t->kind != tokvar || coef_varrec->stringvar != 0)
4217+
snerr(": Cannot find coefficient variable");
4218+
LINK->t = LINK->t->next;
4219+
4220+
require(tokrp, LINK);
4221+
4222+
free_dim_stringvar(elts_varrec);
4223+
PhreeqcPtr->free_check_null(coef_varrec->UU.U0.arr);
4224+
coef_varrec->UU.U0.arr = NULL;
4225+
/*
4226+
* Call subroutine
4227+
*/
4228+
std::string eq = PhreeqcPtr->species_equation(species_name, stoichiometry);
4229+
4230+
// put type as return value
4231+
n.stringval = true;
4232+
n.UU.sval = PhreeqcPtr->string_duplicate(eq.c_str());
4233+
4234+
/*
4235+
* fill in varrec structure
4236+
*/
4237+
4238+
size_t count = stoichiometry.size();
4239+
*count_varrec->UU.U0.val = (LDBLE)count;
4240+
/*
4241+
* malloc space
4242+
*/
4243+
elts_varrec->UU.U1.sarr = (char**)PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(char*));
4244+
if (elts_varrec->UU.U1.sarr == NULL)
4245+
{
4246+
PhreeqcPtr->malloc_error();
4247+
#if !defined(R_SO)
4248+
exit(4);
4249+
#endif
4250+
}
4251+
coef_varrec->UU.U0.arr = (LDBLE*)PhreeqcPtr->PHRQ_malloc((count + 1) * sizeof(LDBLE));
4252+
if (coef_varrec->UU.U0.arr == NULL)
4253+
{
4254+
PhreeqcPtr->malloc_error();
4255+
#if !defined(R_SO)
4256+
exit(4);
4257+
#endif
4258+
}
4259+
4260+
// first position not used
4261+
elts_varrec->UU.U1.sarr[0] = NULL;
4262+
coef_varrec->UU.U0.arr[0] = 0;
4263+
4264+
// set dims for Basic array
4265+
for (i = 0; i < maxdims; i++)
4266+
{
4267+
elts_varrec->dims[i] = 0;
4268+
coef_varrec->dims[i] = 0;
4269+
}
4270+
// set dims for first dimension and number of dims
4271+
elts_varrec->dims[0] = (long)(count + 1);
4272+
coef_varrec->dims[0] = (long)(count + 1);
4273+
elts_varrec->numdims = 1;
4274+
coef_varrec->numdims = 1;
4275+
4276+
// fill in arrays
4277+
i = 1;
4278+
for (std::vector<std::pair<std::string, double > >::iterator it = stoichiometry.begin(); it != stoichiometry.end(); it++)
4279+
{
4280+
elts_varrec->UU.U1.sarr[i] = PhreeqcPtr->string_duplicate((it->first).c_str());
4281+
coef_varrec->UU.U0.arr[i] = it->second;
4282+
i++;
4283+
}
4284+
}
4285+
break;
4286+
40834287
case toksr:
40844288
{
40854289
const char* str = stringfactor(STR1, LINK);
@@ -8088,6 +8292,10 @@ const std::map<const std::string, PBasic::BASIC_TOKEN>::value_type temp_tokens[]
80888292
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("soln_vol", PBasic::toksoln_vol),
80898293
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("species_formula", PBasic::tokspecies_formula),
80908294
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("species_formula$", PBasic::tokspecies_formula_),
8295+
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("phase_equation", PBasic::tokphase_equation),
8296+
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("phase_equation$", PBasic::tokphase_equation_),
8297+
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("species_equation", PBasic::tokspecies_equation),
8298+
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("species_equation$", PBasic::tokspecies_equation_),
80918299
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("sr", PBasic::toksr),
80928300
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("step_no", PBasic::tokstep_no),
80938301
std::map<const std::string, PBasic::BASIC_TOKEN>::value_type("str_e$", PBasic::tokstr_e_),

src/phast/PhreeqcRM/src/IPhreeqcPhast/IPhreeqc/phreeqcpp/PBasic.h

+4
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ class PBasic: public PHRQ_base
323323
toksoln_vol,
324324
tokspecies_formula,
325325
tokspecies_formula_,
326+
tokphase_equation,
327+
tokphase_equation_,
328+
tokspecies_equation,
329+
tokspecies_equation_,
326330
toksr,
327331
tokstep_no,
328332
tokstr_e_,

src/phast/PhreeqcRM/src/IPhreeqcPhast/IPhreeqc/phreeqcpp/Phreeqc.h

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ class Phreeqc
167167
std::string kinetics_formula(std::string kinetics_name, cxxNameDouble& stoichiometry);
168168
std::string phase_formula(std::string phase_name, cxxNameDouble& stoichiometry);
169169
std::string species_formula(std::string phase_name, cxxNameDouble& stoichiometry);
170+
std::string phase_equation(std::string phase_name, std::vector<std::pair<std::string, double> >& stoichiometry);
171+
std::string species_equation(std::string species_name, std::vector<std::pair<std::string, double> >& stoichiometry);
170172
LDBLE list_ss(std::string ss_name, cxxNameDouble& composition);
171173
int system_total_elements(void);
172174
int system_total_si(void);

src/phast/PhreeqcRM/src/IPhreeqcPhast/IPhreeqc/phreeqcpp/basicsubs.cpp

+103
Original file line numberDiff line numberDiff line change
@@ -3009,6 +3009,109 @@ species_formula(std::string phase_name, cxxNameDouble& stoichiometry)
30093009
return (formula);
30103010
}
30113011

3012+
/* ---------------------------------------------------------------------- */
3013+
std::string Phreeqc::
3014+
phase_equation(std::string phase_name, std::vector<std::pair<std::string, double> >& stoichiometry)
3015+
/* ---------------------------------------------------------------------- */
3016+
{
3017+
/*
3018+
* Returns equation
3019+
* Also returns arrays of species and stoichiometry in stoichiometry
3020+
*/
3021+
stoichiometry.clear();
3022+
std::ostringstream eq, lhs, rhs;
3023+
int j = -1;
3024+
class phase* phase_ptr = phase_bsearch(phase_name.c_str(), &j, FALSE);
3025+
bool rhs_started = false;
3026+
bool lhs_started = false;
3027+
if (phase_ptr != NULL)
3028+
{
3029+
std::vector<rxn_token>::iterator it = phase_ptr->rxn.Get_tokens().begin();
3030+
for (; it->name != NULL; it++)
3031+
{
3032+
if (!lhs_started)
3033+
{
3034+
std::pair<std::string, double> item(phase_ptr->formula, it->coef);
3035+
stoichiometry.push_back(item);
3036+
}
3037+
else
3038+
{
3039+
std::pair<std::string, double> item(it->name, it->coef);
3040+
stoichiometry.push_back(item);
3041+
}
3042+
if (it->coef < 0.0)
3043+
{
3044+
if (lhs_started) lhs << "+ ";
3045+
if (it->coef != -1.0)
3046+
{
3047+
lhs << -it->coef;
3048+
}
3049+
lhs << it->name << " ";
3050+
lhs_started = true;
3051+
}
3052+
else if (it->coef > 0.0)
3053+
{
3054+
if (rhs_started) rhs << "+ ";
3055+
if (it->coef != 1.0)
3056+
{
3057+
rhs << it->coef;
3058+
}
3059+
rhs << it->name << " ";
3060+
rhs_started = true;
3061+
}
3062+
}
3063+
}
3064+
eq << lhs.str() << "= " << rhs.str();
3065+
return (eq.str());
3066+
}
3067+
3068+
/* ---------------------------------------------------------------------- */
3069+
std::string Phreeqc::
3070+
species_equation(std::string species_name, std::vector<std::pair<std::string, double> >& stoichiometry)
3071+
/* ---------------------------------------------------------------------- */
3072+
{
3073+
/*
3074+
* Returns equation
3075+
* Also returns arrays of species and stoichiometry in stoichiometry
3076+
*/
3077+
stoichiometry.clear();
3078+
std::ostringstream eq, lhs, rhs;;
3079+
class species* s_ptr = s_search(species_name.c_str());
3080+
bool rhs_started = false;
3081+
bool lhs_started = false;
3082+
if (s_ptr != NULL)
3083+
{
3084+
std::vector<rxn_token>::iterator it = s_ptr->rxn.Get_tokens().begin();
3085+
for ( ; it->name != NULL; it++)
3086+
{
3087+
std::pair<std::string, double> item(it->name, it->coef);
3088+
stoichiometry.push_back(item);
3089+
if (it->coef > 0.0)
3090+
{
3091+
if (lhs_started) lhs << "+ ";
3092+
if (it->coef != 1.0)
3093+
{
3094+
lhs << it->coef;
3095+
}
3096+
lhs << it->name << " ";
3097+
lhs_started = true;
3098+
}
3099+
else if (it->coef < 0.0)
3100+
{
3101+
if (rhs_started) rhs << "+ ";
3102+
if (it->coef != -1.0)
3103+
{
3104+
rhs << -it->coef;
3105+
}
3106+
rhs << it->name << " ";
3107+
rhs_started = true;
3108+
}
3109+
}
3110+
}
3111+
eq << lhs.str() << "= " << rhs.str();
3112+
return (eq.str());
3113+
}
3114+
30123115
/* ---------------------------------------------------------------------- */
30133116
int Phreeqc::
30143117
system_total_elements(void)

0 commit comments

Comments
 (0)