New format for SOLID_SOLUTION_RAW.

All ss test cases run on Windows (but may not be correct).

git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/branches/ErrorHandling@6072 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
David L Parkhurst 2012-01-17 23:35:39 +00:00
parent d051a77711
commit 02ece436f4
5 changed files with 213 additions and 71 deletions

157
SS.cxx
View File

@ -122,23 +122,23 @@ cxxSS::dump_raw(std::ostream & s_oss, unsigned int indent) const
indent1.append(Utilities::INDENT);
// S_S element and attributes
s_oss << indent0 << "-name " << this->name << "\n";
//s_oss << indent0 << "-total_moles " << this->total_moles << "\n";
s_oss << indent1 << "-a0 " << this->a0 << "\n";
s_oss << indent1 << "-a1 " << this->a1 << "\n";
s_oss << indent1 << "-ag0 " << this->ag0 << "\n";
s_oss << indent1 << "-ag1 " << this->ag1 << "\n";
s_oss << indent1 << "-miscibility " << this->miscibility << "\n";
//s_oss << indent0 << "-spinodal " << this->spinodal << "\n";
//s_oss << indent0 << "-tk " << this->tk << "\n";
s_oss << indent1 << "-xb1 " << this->xb1 << "\n";
s_oss << indent1 << "-xb2 " << this->xb2 << "\n";
//s_oss << indent1 << "-components " << "\n";
//this->comps.dump_raw(s_oss, indent + 2);
//s_oss << indent0 << "-ss_name " << this->name << "\n";
s_oss << indent0 << "-total_moles " << this->total_moles << "\n";
//s_oss << indent0 << "-dn " << this->dn << "\n";
s_oss << indent0 << "-a0 " << this->a0 << "\n";
s_oss << indent0 << "-a1 " << this->a1 << "\n";
s_oss << indent0 << "-ag0 " << this->ag0 << "\n";
s_oss << indent0 << "-ag1 " << this->ag1 << "\n";
s_oss << indent0 << "-miscibility " << this->miscibility << "\n";
s_oss << indent0 << "-spinodal " << this->spinodal << "\n";
s_oss << indent0 << "-tk " << this->tk << "\n";
s_oss << indent0 << "-xb1 " << this->xb1 << "\n";
s_oss << indent0 << "-xb2 " << this->xb2 << "\n";
s_oss << indent0 << "-input_case " << this->input_case << "\n";
for (size_t i = 0; i < this->ss_comps.size(); i++)
{
s_oss << indent1 << "-components " << "\n";
this->ss_comps[i].dump_raw(s_oss, indent + 2);
s_oss << indent0 << "-component " << this->ss_comps[i].Get_name() << "\n";
this->ss_comps[i].dump_raw(s_oss, indent + 1);
}
}
@ -151,7 +151,7 @@ cxxSS::read_raw(CParser & parser, bool check)
if (vopts.empty())
{
vopts.reserve(10);
vopts.push_back("name"); // 0
vopts.push_back("ss_name_not_used"); // 0
vopts.push_back("total_moles"); // 1
vopts.push_back("a0"); // 2
vopts.push_back("a1"); // 3
@ -163,6 +163,12 @@ cxxSS::read_raw(CParser & parser, bool check)
vopts.push_back("xb2"); // 9
vopts.push_back("ag0"); // 10
vopts.push_back("ag1"); // 11
vopts.push_back("component"); // 12
vopts.push_back("input_case"); //13
//vopts.push_back("initial_moles"); // 13
//vopts.push_back("fraction_x"); // 13
//vopts.push_back("log10_lambda"); // 13
//vopts.push_back("log10_fraction_x"); // 13
}
std::istream::pos_type ptr;
@ -182,15 +188,24 @@ cxxSS::read_raw(CParser & parser, bool check)
//bool tk_defined(false);
bool xb1_defined(false);
bool xb2_defined(false);
bool useLastLine = false;
for (;;)
{
int opt = parser.get_option(vopts, next_char);
int opt;
if (useLastLine == false)
{
opt = parser.get_option(vopts, next_char);
}
else
{
opt = parser.getOptionFromLastLine(vopts, next_char);
}
if (opt == CParser::OPT_DEFAULT)
{
opt = opt_save;
}
useLastLine = false;
switch (opt)
{
case CParser::OPT_EOF:
@ -205,7 +220,7 @@ cxxSS::read_raw(CParser & parser, bool check)
//parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE);
break;
case 0: // name
case 0: // name not used
if (!(parser.get_iss() >> str))
{
this->name.clear();
@ -222,15 +237,13 @@ cxxSS::read_raw(CParser & parser, bool check)
break;
case 1: // total_moles
/*
if (!(parser.get_iss() >> this->total_moles))
{
this->total_moles = 0;
parser.incr_input_error();
parser.error_msg("Expected numeric value for total_moles.", PHRQ_io::OT_CONTINUE);
}
total_moles_defined = true;
*/
if (!(parser.get_iss() >> this->total_moles))
{
this->total_moles = 0;
parser.incr_input_error();
parser.error_msg("Expected numeric value for total_moles.", PHRQ_io::OT_CONTINUE);
}
//total_moles_defined = true;
opt_save = CParser::OPT_DEFAULT;
break;
@ -259,11 +272,43 @@ cxxSS::read_raw(CParser & parser, bool check)
break;
case 4: // components
case 12: // component
{
cxxSScomp comp(io);
comp.read_raw(parser, false);
this->ss_comps.push_back(comp);
if (!(parser.get_iss() >> str))
{
this->name.clear();
parser.incr_input_error();
parser.error_msg("Expected string value for component name.",
PHRQ_io::OT_CONTINUE);
}
else
{
cxxSScomp temp_comp(io);
temp_comp.Set_name(str);
cxxSScomp * comp_ptr = this->Find(str.c_str());
if (comp_ptr)
{
temp_comp = *comp_ptr;
}
temp_comp.read_raw(parser, false);
if (comp_ptr)
{
for (size_t j = 0; j < this->ss_comps.size(); j++)
{
if (Utilities::strcmp_nocase(this->ss_comps[j].Get_name().c_str(), str.c_str()) == 0)
{
this->ss_comps[j] = temp_comp;
}
}
}
else
{
this->ss_comps.push_back(temp_comp);
}
useLastLine = true;
}
}
opt_save = CParser::OPT_DEFAULT;
break;
@ -280,28 +325,24 @@ cxxSS::read_raw(CParser & parser, bool check)
break;
case 6: // spinodal
/*
if (!(parser.get_iss() >> this->spinodal))
{
this->spinodal = 0;
parser.incr_input_error();
parser.error_msg("Expected boolean value for spinodal.", PHRQ_io::OT_CONTINUE);
}
spinodal_defined = true;
*/
if (!(parser.get_iss() >> this->spinodal))
{
this->spinodal = 0;
parser.incr_input_error();
parser.error_msg("Expected boolean value for spinodal.", PHRQ_io::OT_CONTINUE);
}
//spinodal_defined = true;
opt_save = CParser::OPT_DEFAULT;
break;
case 7: // tk
/*
if (!(parser.get_iss() >> this->tk))
{
this->tk = 0;
parser.incr_input_error();
parser.error_msg("Expected numeric value for tk.", PHRQ_io::OT_CONTINUE);
}
tk_defined = true;
*/
if (!(parser.get_iss() >> this->tk))
{
this->tk = 0;
parser.incr_input_error();
parser.error_msg("Expected numeric value for tk.", PHRQ_io::OT_CONTINUE);
}
//tk_defined = true;
opt_save = CParser::OPT_DEFAULT;
break;
@ -352,7 +393,23 @@ cxxSS::read_raw(CParser & parser, bool check)
ag1_defined = true;
opt_save = CParser::OPT_DEFAULT;
break;
case 13: // input_case
{
int i;
if (!(parser.get_iss() >> i))
{
this->input_case = cxxSS::SS_PARM_NONE;
parser.incr_input_error();
parser.error_msg("Expected integer value for parameter type.", PHRQ_io::OT_CONTINUE);
}
else
{
this->input_case = (cxxSS::SS_PARAMETER_TYPE) i;
}
}
//spinodal_defined = true;
opt_save = CParser::OPT_DEFAULT;
break;
}
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)

2
SS.h
View File

@ -105,7 +105,7 @@ class cxxSS: public PHRQ_base
void Set_tk(LDBLE t) {this->tk = t;}
SS_PARAMETER_TYPE Get_input_case(void) {return this->input_case;}
void Set_input_case(SS_PARAMETER_TYPE t) {this->input_case = t;}
std::vector<LDBLE> Get_p(void) {return this->p;}
std::vector<LDBLE> & Get_p(void) {return this->p;}
void Set_p(const std::vector<LDBLE> & t) {this->p = t;}
protected:
std::string name;

View File

@ -130,11 +130,90 @@ cxxSSassemblage::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out)
SSs.begin(); it != SSs.end(); ++it)
{
s_oss << indent1;
s_oss << "-solid_solution" << "\n";
s_oss << "-solid_solution " << it->first << "\n";
(*it).second.dump_raw(s_oss, indent + 2);
}
}
void
cxxSSassemblage::read_raw(CParser & parser, bool check)
{
static std::vector < std::string > vopts;
if (vopts.empty())
{
vopts.reserve(10);
vopts.push_back("solid_solution"); // 0
}
std::istream::pos_type ptr;
std::istream::pos_type next_char;
std::string token;
int opt_save;
bool useLastLine(false);
cxxSS *ss_ptr = NULL;
// Read SSassemblage number and description
this->read_number_description(parser);
opt_save = CParser::OPT_ERROR;
for (;;)
{
int opt;
if (useLastLine == false)
{
opt = parser.get_option(vopts, next_char);
}
else
{
opt = parser.getOptionFromLastLine(vopts, next_char);
}
if (opt == CParser::OPT_DEFAULT)
{
opt = opt_save;
}
switch (opt)
{
case CParser::OPT_EOF:
break;
case CParser::OPT_KEYWORD:
break;
case CParser::OPT_DEFAULT:
case CParser::OPT_ERROR:
opt = CParser::OPT_EOF;
parser.
error_msg("Unknown input in SOLID_SOLUTIONS_RAW or SOLID_SOLUTIONS_MODIFY keyword.",
PHRQ_io::OT_CONTINUE);
parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE);
useLastLine = false;
break;
case 0: // solid_solution
{
std::string str;
if (!(parser.get_iss() >> str))
{
parser.incr_input_error();
parser.error_msg("Expected string value for solid solution name.",
PHRQ_io::OT_CONTINUE);
}
cxxSS temp_ss(this->Get_io());
temp_ss.Set_name(str);
ss_ptr = this->Find(str);
if (ss_ptr)
{
temp_ss = *ss_ptr;
}
temp_ss.read_raw(parser, false);
this->SSs[str] = temp_ss;
}
useLastLine = true;
break;
}
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
break;
}
}
#ifdef SKIP
void
cxxSSassemblage::read_raw(CParser & parser, bool check)
{
@ -219,7 +298,7 @@ cxxSSassemblage::read_raw(CParser & parser, bool check)
break;
}
}
#endif
#ifdef USE_MPI
/* ---------------------------------------------------------------------- */
void

View File

@ -76,20 +76,20 @@ cxxSScomp::dump_raw(std::ostream & s_oss, unsigned int indent) const
// Pure_Phase element and attributes
if (this->name.size() != 0)
s_oss << indent0 << "-name " << this->name << "\n";
//if (this->name.size() != 0)
// s_oss << indent0 << "-name " << this->name << "\n";
//if (this->add_formula.size() != 0)
// s_oss << indent1 << "-add_formula " << this->add_formula << "\n";
s_oss << indent1 << "-initial_moles " << this->initial_moles << "\n";
s_oss << indent1 << "-moles " << this->moles << "\n";
s_oss << indent1 << "-initial_moles " << this->init_moles << "\n";
s_oss << indent1 << "-delta " << this->delta << "\n";
s_oss << indent1 << "-fraction_x " << this->fraction_x << "\n";
s_oss << indent1 << "-log10_lambda " << this->log10_lambda << "\n";
s_oss << indent1 << "-log10_fraction_x " << this->log10_fraction_x << "\n";
s_oss << indent1 << "-dn " << this->dn << "\n";
s_oss << indent1 << "-dnc " << this->dnc << "\n";
s_oss << indent1 << "-dnb " << this->dnb << "\n";
s_oss << indent0 << "-initial_moles " << this->initial_moles << "\n";
s_oss << indent0 << "-moles " << this->moles << "\n";
s_oss << indent0 << "-init_moles " << this->init_moles << "\n";
s_oss << indent0 << "-delta " << this->delta << "\n";
s_oss << indent0 << "-fraction_x " << this->fraction_x << "\n";
s_oss << indent0 << "-log10_lambda " << this->log10_lambda << "\n";
s_oss << indent0 << "-log10_fraction_x " << this->log10_fraction_x << "\n";
//s_oss << indent0 << "-dn " << this->dn << "\n";
//s_oss << indent0 << "-dnc " << this->dnc << "\n";
//s_oss << indent0 << "-dnb " << this->dnb << "\n";
}
void
@ -101,7 +101,7 @@ cxxSScomp::read_raw(CParser & parser, bool check)
if (vopts.empty())
{
vopts.reserve(10);
vopts.push_back("name"); // 0
vopts.push_back("name_not_used"); // 0
vopts.push_back("initial_moles"); // 1
vopts.push_back("moles"); // 2
vopts.push_back("init_moles"); // 3
@ -109,9 +109,9 @@ cxxSScomp::read_raw(CParser & parser, bool check)
vopts.push_back("fraction_x"); // 5
vopts.push_back("log10_lambda"); // 6
vopts.push_back("log10_fraction_x"); // 7
vopts.push_back("dn"); // 8
vopts.push_back("dnc"); // 9
vopts.push_back("dnb"); // 9
vopts.push_back("dn_not_used"); // 8
vopts.push_back("dnc_not_used"); // 9
vopts.push_back("dnb_not_used"); // 10
}
std::istream::pos_type ptr;

View File

@ -9706,8 +9706,14 @@ read_solid_solutions(void)
case OPTION_DEFAULT:
if(ss_ptr)
{
comps.insert(comps.begin(), *comp1_ptr);
comps.insert(comps.begin(), *comp0_ptr);
if (comp1_ptr)
{
comps.insert(comps.begin(), *comp1_ptr);
}
if (comp0_ptr)
{
comps.insert(comps.begin(), *comp0_ptr);
}
ss_ptr->Set_ss_comps(comps);
temp_ss_assemblage.Get_SSs()[ss_ptr->Get_name()] = *ss_ptr;
delete ss_ptr;