Merge branch 'log10molalities' into gasphasepressures

This commit is contained in:
David Parkhurst 2021-03-02 20:58:44 -07:00
commit c4f9d291db
3 changed files with 89 additions and 2 deletions

View File

@ -83,6 +83,7 @@ cxxSolution::operator =(const cxxSolution &rhs)
this->isotopes = rhs.isotopes;
this->species_map = rhs.species_map;
this->log_gamma_map = rhs.log_gamma_map;
this->log_molalities_map = rhs.log_molalities_map;
if (this->initial_data)
delete initial_data;
if (rhs.initial_data != NULL)
@ -327,6 +328,19 @@ cxxSolution::dump_raw(std::ostream & s_oss, unsigned int indent, int *n_out) con
s_oss << it->first << " " << it->second << "\n";
}
}
// log_molalities_map
if (log_molalities_map.size() > 0)
{
s_oss << indent1;
s_oss << "-log_molalities_map" << "\n";
std::map<int, double>::const_iterator it = this->log_molalities_map.begin();
for (; it != log_molalities_map.end(); it++)
{
s_oss << indent2;
s_oss << it->first << " " << it->second << "\n";
}
}
return;
}
@ -1013,7 +1027,32 @@ cxxSolution::read_raw(CParser & parser, bool check)
}
opt_save = CParser::OPT_DEFAULT;
break;
case 27: // log_molalities_map
{
int s_num;
if (parser.peek_token() != CParser::TT_EMPTY)
{
if (!(parser.get_iss() >> s_num))
{
parser.incr_input_error();
parser.error_msg("Expected integer for species number.",
PHRQ_io::OT_CONTINUE);
}
else
{
double d;
if (!(parser.get_iss() >> d))
{
parser.incr_input_error();
parser.error_msg("Expected double for species molality.",
PHRQ_io::OT_CONTINUE);
}
this->log_molalities_map[s_num] = d;
}
}
opt_save = 27;
}
break;
}
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD)
break;
@ -1415,6 +1454,19 @@ cxxSolution::add(const cxxSolution & addee, LDBLE extensive)
this->log_gamma_map[git->first] = git->second;
}
}
// Add molalities
std::map<int, double>::const_iterator mit = addee.log_molalities_map.begin();
for (; mit != addee.log_molalities_map.end(); mit++)
{
if (this->log_molalities_map.find(mit->first) != this->log_molalities_map.end())
{
this->log_molalities_map[mit->first] = this->log_molalities_map[mit->first] * f1 + mit->second * f2;
}
else
{
this->log_molalities_map[mit->first] = mit->second;
}
}
}
}
@ -1618,6 +1670,18 @@ cxxSolution::Serialize(Dictionary & dictionary, std::vector < int >&ints,
doubles.push_back(it->second);
}
}
/*
* log_molalities_map
*/
ints.push_back((int)log_molalities_map.size());
{
std::map < int, double >::iterator it;
for (it = log_molalities_map.begin(); it != log_molalities_map.end(); it++)
{
ints.push_back(it->first);
doubles.push_back(it->second);
}
}
}
/* ---------------------------------------------------------------------- */
@ -1692,6 +1756,17 @@ cxxSolution::Deserialize(Dictionary & dictionary, std::vector < int >&ints, std:
log_gamma_map[ints[ii++]] = doubles[dd++];
}
}
/*
* log_molalities_map
*/
{
log_molalities_map.clear();
int n = ints[ii++];
for (int i = 0; i < n; i++)
{
log_molalities_map[ints[ii++]] = doubles[dd++];
}
}
}
@ -1722,6 +1797,7 @@ const std::vector< std::string >::value_type temp_vopts[] = {
std::vector< std::string >::value_type("soln_vol"), // 23
std::vector< std::string >::value_type("species_map"), // 24
std::vector< std::string >::value_type("log_gamma_map"), // 25
std::vector< std::string >::value_type("potential") // 26
std::vector< std::string >::value_type("potential"), // 26
std::vector< std::string >::value_type("log_molalities_map") // 27
};
const std::vector< std::string > cxxSolution::vopts(temp_vopts, temp_vopts + sizeof temp_vopts / sizeof temp_vopts[0]);

View File

@ -66,6 +66,7 @@ class cxxSolution:public cxxNumKeyword
cxxNameDouble & Get_species_gamma(void) {return this->species_gamma;}
std::map<int, double> & Get_species_map(void) {return this->species_map;}
std::map<int, double> & Get_log_gamma_map(void) {return this->log_gamma_map;}
std::map<int, double>& Get_log_molalities_map(void) { return this->log_molalities_map; }
std::map < std::string, cxxSolutionIsotope > & Get_isotopes(void) {return this->isotopes;}
const std::map < std::string, cxxSolutionIsotope > & Get_isotopes(void)const {return this->isotopes;}
void Set_isotopes(const std::map < std::string, cxxSolutionIsotope > &iso ) {this->isotopes = iso;}
@ -141,6 +142,7 @@ class cxxSolution:public cxxNumKeyword
const static std::vector < std::string > vopts;
std::map<int, double> species_map;
std::map<int, double> log_gamma_map;
std::map<int, double> log_molalities_map;
};
#endif // !defined(SOLUTION_H_INCLUDED)

View File

@ -1687,6 +1687,15 @@ xsolution_save(int n_user)
temp_solution.Get_log_gamma_map()[s_x[i]->number] = s_x[i]->lg;
}
}
// saves molalities
temp_solution.Get_log_molalities_map().clear();
for (int i = 0; i < this->count_s_x; i++)
{
if (s_x[i]->type <= H2O)
{
temp_solution.Get_log_molalities_map()[s_x[i]->number] = s_x[i]->lm;
}
}
}
/*
* Save solution