exchange_modify is working.

changed list of comps to map of comps.

made sure that description changes were captured for solution, equilibrium_phases, and exchange.

surface is next.

git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@3725 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
David L Parkhurst 2009-10-27 22:57:49 +00:00
parent b9e38f4da8
commit f015759286
7 changed files with 196 additions and 112 deletions

View File

@ -188,7 +188,7 @@ cxxExchComp::get_master()
} }
struct exch_comp * struct exch_comp *
cxxExchComp::cxxExchComp2exch_comp(std::list < cxxExchComp > &el) cxxExchComp::cxxExchComp2exch_comp(std::map < std::string, cxxExchComp > &el)
// //
// Builds exch_comp structure from of cxxExchComp // Builds exch_comp structure from of cxxExchComp
// //
@ -200,20 +200,20 @@ cxxExchComp::cxxExchComp2exch_comp(std::list < cxxExchComp > &el)
malloc_error(); malloc_error();
int i = 0; int i = 0;
for (std::list < cxxExchComp >::iterator it = el.begin(); it != el.end(); for (std::map < std::string, cxxExchComp >::iterator it = el.begin(); it != el.end();
++it) ++it)
{ {
exch_comp_ptr[i].formula = it->formula; exch_comp_ptr[i].formula = (*it).second.formula;
exch_comp_ptr[i].formula_z = it->formula_z; exch_comp_ptr[i].formula_z = (*it).second.formula_z;
exch_comp_ptr[i].totals = it->totals.elt_list(); exch_comp_ptr[i].totals = (*it).second.totals.elt_list();
exch_comp_ptr[i].moles = it->moles; exch_comp_ptr[i].moles = (*it).second.moles;
exch_comp_ptr[i].formula_totals = it->formula_totals.elt_list(); exch_comp_ptr[i].formula_totals = (*it).second.formula_totals.elt_list();
exch_comp_ptr[i].la = it->la; exch_comp_ptr[i].la = (*it).second.la;
exch_comp_ptr[i].charge_balance = it->charge_balance; exch_comp_ptr[i].charge_balance = (*it).second.charge_balance;
exch_comp_ptr[i].phase_name = it->phase_name; exch_comp_ptr[i].phase_name = (*it).second.phase_name;
exch_comp_ptr[i].phase_proportion = it->phase_proportion; exch_comp_ptr[i].phase_proportion = (*it).second.phase_proportion;
exch_comp_ptr[i].rate_name = it->rate_name; exch_comp_ptr[i].rate_name = (*it).second.rate_name;
exch_comp_ptr[i].master = it->get_master(); exch_comp_ptr[i].master = (*it).second.get_master();
i++; i++;
} }
return (exch_comp_ptr); return (exch_comp_ptr);
@ -282,40 +282,41 @@ cxxExchComp::dump_raw(std::ostream & s_oss, unsigned int indent) const
// Exch_Comp element and attributes // Exch_Comp element and attributes
s_oss << indent0 << "-formula " << this-> s_oss << indent0 << "-formula " << this->formula << std::endl;
formula << std::endl;
s_oss << indent0 << "-moles " << this->moles << std::endl; //s_oss << indent1 << "# critical values" << std::endl;
s_oss << indent0 << "-la " << this->la << std::endl;
s_oss << indent0 << "-charge_balance " << this-> // totals
charge_balance << std::endl; s_oss << indent1;
s_oss << "-totals" << std::endl;
this->totals.dump_raw(s_oss, indent + 2);
s_oss << indent1 << "-charge_balance " << this->charge_balance << std::endl;
//s_oss << indent1 << "# Noncritical values" << std::endl;
s_oss << indent1 << "-moles " << this->moles << std::endl;
s_oss << indent1 << "-la " << this->la << std::endl;
if (this->phase_name != NULL) if (this->phase_name != NULL)
{ {
s_oss << indent0 << "-phase_name " << this-> s_oss << indent1 << "-phase_name " << this->phase_name << std::endl;
phase_name << std::endl;
} }
if (this->rate_name != NULL) if (this->rate_name != NULL)
{ {
s_oss << indent0 << "-rate_name " << this-> s_oss << indent1 << "-rate_name " << this->rate_name << std::endl;
rate_name << std::endl;
} }
s_oss << indent0 << "-phase_proportion " << this-> s_oss << indent1 << "-phase_proportion " << this->phase_proportion << std::endl;
phase_proportion << std::endl; s_oss << indent1 << "-formula_z " << this->formula_z << std::endl;
s_oss << indent0 << "-formula_z " << this->
formula_z << std::endl;
// totals
s_oss << indent0;
s_oss << "-totals" << std::endl;
this->totals.dump_raw(s_oss, indent + 1);
// formula_totals // formula_totals
s_oss << indent0; s_oss << indent1;
s_oss << "-formula_totals" << std::endl; s_oss << "-formula_totals" << std::endl;
this->formula_totals.dump_raw(s_oss, indent + 1); this->formula_totals.dump_raw(s_oss, indent + 2);
} }
void void
cxxExchComp::read_raw(CParser & parser) cxxExchComp::read_raw(CParser & parser, bool check)
{ {
std::string str; std::string str;
@ -496,36 +497,39 @@ cxxExchComp::read_raw(CParser & parser)
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
break; break;
} }
// members that must be defined if (check)
if (formula_defined == false)
{ {
parser.incr_input_error(); // members that must be defined
parser.error_msg("Formula not defined for ExchComp input.", if (formula_defined == false)
CParser::OT_CONTINUE); {
} parser.incr_input_error();
if (moles_defined == false) parser.error_msg("Formula not defined for ExchComp input.",
{ CParser::OT_CONTINUE);
parser.incr_input_error(); }
parser.error_msg("Moles not defined for ExchComp input.", if (moles_defined == false)
CParser::OT_CONTINUE); {
} parser.incr_input_error();
if (la_defined == false) parser.error_msg("Moles not defined for ExchComp input.",
{ CParser::OT_CONTINUE);
parser.incr_input_error(); }
parser.error_msg("La not defined for ExchComp input.", if (la_defined == false)
CParser::OT_CONTINUE); {
} parser.incr_input_error();
if (charge_balance_defined == false) parser.error_msg("La not defined for ExchComp input.",
{ CParser::OT_CONTINUE);
parser.incr_input_error(); }
parser.error_msg("Charge_balance not defined for ExchComp input.", if (charge_balance_defined == false)
CParser::OT_CONTINUE); {
} parser.incr_input_error();
if (formula_z_defined == false) parser.error_msg("Charge_balance not defined for ExchComp input.",
{ CParser::OT_CONTINUE);
parser.incr_input_error(); }
parser.error_msg("Formula_z not defined for ExchComp input.", if (formula_z_defined == false)
CParser::OT_CONTINUE); {
parser.incr_input_error();
parser.error_msg("Formula_z not defined for ExchComp input.",
CParser::OT_CONTINUE);
}
} }
} }
void void

View File

@ -22,14 +22,14 @@ class cxxExchComp
struct master *get_master(); struct master *get_master();
static struct exch_comp *cxxExchComp2exch_comp(std::list < cxxExchComp > static struct exch_comp *cxxExchComp2exch_comp(std::map < std::string, cxxExchComp >
&el); &el);
void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_xml(std::ostream & os, unsigned int indent = 0) const;
void dump_raw(std::ostream & s_oss, unsigned int indent) const; void dump_raw(std::ostream & s_oss, unsigned int indent) const;
void read_raw(CParser & parser); void read_raw(CParser & parser, bool check=true);
char *get_formula() const char *get_formula() const
{ {

View File

@ -46,7 +46,8 @@ cxxNumKeyword()
for (i = 0; i < exchange_ptr->count_comps; i++) for (i = 0; i < exchange_ptr->count_comps; i++)
{ {
cxxExchComp ec(&(exchange_ptr->comps[i])); cxxExchComp ec(&(exchange_ptr->comps[i]));
exchComps.push_back(ec); std::string str(ec.get_formula());
exchComps[str] = ec;
} }
@ -160,7 +161,8 @@ cxxNumKeyword()
ec.set_totals(elt_list, count_elts); ec.set_totals(elt_list, count_elts);
// add to comp list // add to comp list
this->exchComps.push_back(ec); std::string str(ec.get_formula());
this->exchComps[str] = ec;
} }
} }
} }
@ -172,10 +174,10 @@ cxxExchange::~cxxExchange()
bool bool
cxxExchange::get_related_phases() cxxExchange::get_related_phases()
{ {
for (std::list < cxxExchComp >::const_iterator it = for (std::map < std::string, cxxExchComp >::const_iterator it =
this->exchComps.begin(); it != this->exchComps.end(); ++it) this->exchComps.begin(); it != this->exchComps.end(); ++it)
{ {
if (it->get_phase_name() == NULL) if ((*it).second.get_phase_name() == NULL)
continue; continue;
return (true); return (true);
} }
@ -185,10 +187,10 @@ cxxExchange::get_related_phases()
bool bool
cxxExchange::get_related_rate() cxxExchange::get_related_rate()
{ {
for (std::list < cxxExchComp >::const_iterator it = for (std::map < std::string, cxxExchComp >::const_iterator it =
this->exchComps.begin(); it != this->exchComps.end(); ++it) this->exchComps.begin(); it != this->exchComps.end(); ++it)
{ {
if (it->get_rate_name() == NULL) if ((*it).second.get_rate_name() == NULL)
continue; continue;
return (true); return (true);
} }
@ -213,8 +215,7 @@ cxxExchange::cxxExchange2exchange()
exchange_ptr->related_rate = (int) this->get_related_rate(); exchange_ptr->related_rate = (int) this->get_related_rate();
exchange_ptr->pitzer_exchange_gammas = (int) this->pitzer_exchange_gammas; exchange_ptr->pitzer_exchange_gammas = (int) this->pitzer_exchange_gammas;
exchange_ptr->count_comps = (int) this->exchComps.size(); exchange_ptr->count_comps = (int) this->exchComps.size();
exchange_ptr->comps = exchange_ptr->comps = (struct exch_comp *) free_check_null(exchange_ptr->comps);
(struct exch_comp *) free_check_null(exchange_ptr->comps);
exchange_ptr->comps = cxxExchComp::cxxExchComp2exch_comp(this->exchComps); exchange_ptr->comps = cxxExchComp::cxxExchComp2exch_comp(this->exchComps);
return (exchange_ptr); return (exchange_ptr);
} }
@ -244,10 +245,10 @@ cxxExchange::dump_xml(std::ostream & s_oss, unsigned int indent) const
// components // components
s_oss << indent1; s_oss << indent1;
s_oss << "<component " << std::endl; s_oss << "<component " << std::endl;
for (std::list < cxxExchComp >::const_iterator it = exchComps.begin(); for (std::map < std::string, cxxExchComp >::const_iterator it = exchComps.begin();
it != exchComps.end(); ++it) it != exchComps.end(); ++it)
{ {
it->dump_xml(s_oss, indent + 2); (*it).second.dump_xml(s_oss, indent + 2);
} }
return; return;
@ -277,12 +278,12 @@ cxxExchange::dump_raw(std::ostream & s_oss, unsigned int indent) const
pitzer_exchange_gammas << std::endl; pitzer_exchange_gammas << std::endl;
// exchComps structures // exchComps structures
for (std::list < cxxExchComp >::const_iterator it = exchComps.begin(); for (std::map < std::string, cxxExchComp >::const_iterator it = exchComps.begin();
it != exchComps.end(); ++it) it != exchComps.end(); ++it)
{ {
s_oss << indent1; s_oss << indent1;
s_oss << "-component" << std::endl; s_oss << "-component" << std::endl;
it->dump_raw(s_oss, indent + 2); (*it).second.dump_raw(s_oss, indent + 2);
} }
return; return;
@ -353,8 +354,33 @@ cxxExchange::read_raw(CParser & parser, bool check)
case 1: // component case 1: // component
{ {
cxxExchComp ec; cxxExchComp ec;
ec.read_raw(parser);
this->exchComps.push_back(ec); // preliminary read
std::istream::pos_type pos = parser.tellg();
CParser::ECHO_OPTION eo = parser.get_echo_file();
parser.set_echo_file(CParser::EO_NONE);
CParser::ECHO_OPTION eo_s = parser.get_echo_stream();
parser.set_echo_stream(CParser::EO_NONE);
ec.read_raw(parser, false);
parser.set_echo_file(eo);
parser.set_echo_file(eo_s);
if (this->exchComps.find(ec.get_formula()) != this->exchComps.end())
{
cxxExchComp & comp = this->exchComps.find(ec.get_formula())->second;
parser.seekg(pos).clear();
parser.seekg(pos);
comp.read_raw(parser, false);
}
else
{
parser.seekg(pos).clear();
parser.seekg(pos);
cxxExchComp ec1;
ec1.read_raw(parser, false);
std::string str(ec1.get_formula());
this->exchComps[str] = ec1;
}
} }
useLastLine = true; useLastLine = true;
break; break;
@ -375,6 +401,7 @@ cxxExchange::read_raw(CParser & parser, bool check)
} }
} }
} }
#ifdef SKIP
void void
cxxExchange::add(const cxxExchange & addee, double extensive) cxxExchange::add(const cxxExchange & addee, double extensive)
// //
@ -410,7 +437,48 @@ cxxExchange::add(const cxxExchange & addee, double extensive)
//bool pitzer_exchange_gammas; //bool pitzer_exchange_gammas;
this->pitzer_exchange_gammas = addee.pitzer_exchange_gammas; this->pitzer_exchange_gammas = addee.pitzer_exchange_gammas;
} }
#endif
void
cxxExchange::add(const cxxExchange & addee, double extensive)
//
// Add existing exchange to "this" exchange
//
{
// exchComps
if (extensive == 0.0)
return;
for (std::map < std::string, cxxExchComp >::const_iterator itadd =
addee.exchComps.begin(); itadd != addee.exchComps.end(); ++itadd)
{
std::map < std::string, cxxExchComp >::iterator it = this->exchComps.find((*itadd).first);
if (it != this->exchComps.end())
{
(*it).second.add((*itadd).second, extensive);
//bool found = false;
//for (std::list < cxxExchComp >::iterator it = this->exchComps.begin();
// it != this->exchComps.end(); ++it)
//{
// if (it->get_formula() == itadd->get_formula())
// {
// it->add((*itadd), extensive);
// found = true;
// break;
// }
//}
/*if (!found)*/
}
else
{
cxxExchComp exc = (*itadd).second;
exc.multiply(extensive);
//exc.add(*itadd, extensive);
this->exchComps[(*itadd).first] = exc;
}
}
//bool pitzer_exchange_gammas;
this->pitzer_exchange_gammas = addee.pitzer_exchange_gammas;
}
#ifdef USE_MPI #ifdef USE_MPI
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
void void
@ -461,11 +529,11 @@ cxxExchange::totalize()
{ {
this->totals.clear(); this->totals.clear();
// component structures // component structures
for (std::list < cxxExchComp >::const_iterator it = exchComps.begin(); for (std::map < std::string, cxxExchComp >::const_iterator it = exchComps.begin();
it != exchComps.end(); ++it) it != exchComps.end(); ++it)
{ {
this->totals.add_extensive(it->get_totals(), 1.0); this->totals.add_extensive((*it).second.get_totals(), 1.0);
this->totals.add("Charge", it->get_charge_balance()); this->totals.add("Charge", (*it).second.get_charge_balance());
} }
return; return;
} }

View File

@ -43,7 +43,7 @@ class cxxExchange:public cxxNumKeyword
this->pitzer_exchange_gammas = b; this->pitzer_exchange_gammas = b;
} }
std::list < cxxExchComp > &get_exchComps(void) std::map < std::string, cxxExchComp > &get_exchComps(void)
{ {
return (this->exchComps); return (this->exchComps);
} }
@ -64,7 +64,7 @@ class cxxExchange:public cxxNumKeyword
void dump_xml(std::ostream & os, unsigned int indent = 0) const; void dump_xml(std::ostream & os, unsigned int indent = 0) const;
protected: protected:
std::list < cxxExchComp > exchComps; std::map < std::string, cxxExchComp > exchComps;
bool pitzer_exchange_gammas; bool pitzer_exchange_gammas;
cxxNameDouble totals; cxxNameDouble totals;
public: public:

View File

@ -230,16 +230,21 @@ cxxPPassemblage::read_raw(CParser & parser, bool check)
case 1: // component case 1: // component
{ {
std::istream::pos_type pos = parser.tellg();
cxxPPassemblageComp ppComp; cxxPPassemblageComp ppComp;
CParser::ECHO_OPTION eo = parser.get_echo_stream();
// preliminary read
std::istream::pos_type pos = parser.tellg();
CParser::ECHO_OPTION eo = parser.get_echo_file();
parser.set_echo_file(CParser::EO_NONE);
CParser::ECHO_OPTION eo_s = parser.get_echo_stream();
parser.set_echo_stream(CParser::EO_NONE); parser.set_echo_stream(CParser::EO_NONE);
ppComp.read_raw(parser, false); ppComp.read_raw(parser, false);
parser.set_echo_stream(eo); parser.set_echo_file(eo);
parser.set_echo_file(eo_s);
if (this->ppAssemblageComps.find(ppComp.get_name()) != this->ppAssemblageComps.end()) if (this->ppAssemblageComps.find(ppComp.get_name()) != this->ppAssemblageComps.end())
{ {
cxxPPassemblageComp & comp = ppAssemblageComps.find(ppComp.get_name())->second; cxxPPassemblageComp & comp = this->ppAssemblageComps.find(ppComp.get_name())->second;
parser.seekg(pos).clear(); parser.seekg(pos).clear();
parser.seekg(pos); parser.seekg(pos);
comp.read_raw(parser, false); comp.read_raw(parser, false);

View File

@ -373,8 +373,7 @@ read_equilibrium_phases_raw(void)
cxxPPassemblage ex; cxxPPassemblage ex;
ex.read_raw(parser); ex.read_raw(parser);
struct pp_assemblage *pp_assemblage_ptr = struct pp_assemblage *pp_assemblage_ptr = ex.cxxPPassemblage2pp_assemblage();
ex.cxxPPassemblage2pp_assemblage();
int n; int n;
/* /*
@ -1250,6 +1249,8 @@ read_equilibrium_phases_modify(void)
struct pp_assemblage *entity_ptr = entity.cxxPPassemblage2pp_assemblage(); struct pp_assemblage *entity_ptr = entity.cxxPPassemblage2pp_assemblage();
pp_assemblage_free(&(pp_assemblage[n])); pp_assemblage_free(&(pp_assemblage[n]));
pp_assemblage_copy(entity_ptr, &(pp_assemblage[n]), entity_ptr->n_user); pp_assemblage_copy(entity_ptr, &(pp_assemblage[n]), entity_ptr->n_user);
free_check_null(pp_assemblage[n].description);
pp_assemblage[n].description = string_duplicate(entity_ptr->description);
pp_assemblage_free(entity_ptr); pp_assemblage_free(entity_ptr);
free_check_null(entity_ptr); free_check_null(entity_ptr);
@ -1276,6 +1277,25 @@ read_exchange_modify(void)
* *
*/ */
int return_value; int return_value;
// find exchange number
char token[MAX_LENGTH];
char *next;
int l, n_user, n;
next = line;
copy_token(token, &next, &l);
if (copy_token(token, &next, &l) != DIGIT)
{
input_error++;
sprintf(error_string, "Expected exchange number following EXCHANGE_MODIFY.\n%s\n", line_save);
error_msg(error_string, CONTINUE);
return (ERROR);
}
else
{
sscanf(token,"%d", &n_user);
}
/* /*
* Make parser * Make parser
*/ */
@ -1301,23 +1321,6 @@ read_exchange_modify(void)
parser.set_echo_file(CParser::EO_NOKEYWORDS); parser.set_echo_file(CParser::EO_NOKEYWORDS);
} }
// find exchange number
char token[MAX_LENGTH];
char *next;
int l, n_user, n;
next = line;
copy_token(token, &next, &l);
if (copy_token(token, &next, &l) != DIGIT)
{
input_error++;
sprintf(error_string, "Expected exchange number following EXCHANGE_MODIFY.\n%s\n", line_save);
error_msg(error_string, CONTINUE);
return (ERROR);
}
else
{
sscanf(token,"%d", &n_user);
}
if (exchange_bsearch(n_user, &n) == NULL) if (exchange_bsearch(n_user, &n) == NULL)
{ {
input_error++; input_error++;
@ -1334,7 +1337,11 @@ read_exchange_modify(void)
struct exchange *entity_ptr = entity.cxxExchange2exchange(); struct exchange *entity_ptr = entity.cxxExchange2exchange();
exchange_free(&(exchange[n])); exchange_free(&(exchange[n]));
exchange_copy(entity_ptr, &(exchange[n]), entity_ptr->n_user); exchange_copy(entity_ptr, &(exchange[n]), entity_ptr->n_user);
free_check_null(exchange[n].description);
exchange[n].description = string_duplicate(entity_ptr->description);
exchange_free(entity_ptr); exchange_free(entity_ptr);
free_check_null(entity_ptr);
// Need to output the next keyword // Need to output the next keyword
output_msg(OUTPUT_CHECKLINE, "\t%s\n", line); output_msg(OUTPUT_CHECKLINE, "\t%s\n", line);

View File

@ -454,7 +454,7 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const
s_oss << "SOLUTION_RAW " << this->n_user << " " << this-> s_oss << "SOLUTION_RAW " << this->n_user << " " << this->
description << std::endl; description << std::endl;
s_oss << "# Critical values" << std::endl; //s_oss << "# Critical values" << std::endl;
s_oss << indent1; s_oss << indent1;
s_oss << "-temp " << this->tc << std::endl; s_oss << "-temp " << this->tc << std::endl;
@ -476,7 +476,7 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const
s_oss << "-totals" << std::endl; s_oss << "-totals" << std::endl;
this->totals.dump_raw(s_oss, indent + 2); this->totals.dump_raw(s_oss, indent + 2);
s_oss << "# Optional critical values" << std::endl; //s_oss << "# Optional critical values" << std::endl;
// Isotopes // Isotopes
s_oss << indent1; s_oss << indent1;
@ -495,7 +495,7 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent) const
} }
*/ */
s_oss << "# Non-critical values" << std::endl; //s_oss << "# Non-critical values" << std::endl;
s_oss << indent1; s_oss << indent1;
s_oss << "-pH " << this->ph << std::endl; s_oss << "-pH " << this->ph << std::endl;