From 566bfbce3bc5a8616d57f6e26a927aa94f44183c Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Sun, 21 Feb 2021 21:13:05 -0700 Subject: [PATCH] Added GetSpeciesLog10Molalities. Tested OpenMP with VS. Tested MPI with MinGW. Fortran, C, and C++ seem to work. --- phreeqcpp/Solution.cxx | 80 ++++++++++++++++++++++++++++++++++++++++-- phreeqcpp/Solution.h | 2 ++ phreeqcpp/mainsubs.cpp | 9 +++++ 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/phreeqcpp/Solution.cxx b/phreeqcpp/Solution.cxx index 28e11fdf..4b454ab1 100644 --- a/phreeqcpp/Solution.cxx +++ b/phreeqcpp/Solution.cxx @@ -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::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::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]); \ No newline at end of file diff --git a/phreeqcpp/Solution.h b/phreeqcpp/Solution.h index 1ab18654..cecabe78 100644 --- a/phreeqcpp/Solution.h +++ b/phreeqcpp/Solution.h @@ -66,6 +66,7 @@ class cxxSolution:public cxxNumKeyword cxxNameDouble & Get_species_gamma(void) {return this->species_gamma;} std::map & Get_species_map(void) {return this->species_map;} std::map & Get_log_gamma_map(void) {return this->log_gamma_map;} + std::map& 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 species_map; std::map log_gamma_map; + std::map log_molalities_map; }; #endif // !defined(SOLUTION_H_INCLUDED) diff --git a/phreeqcpp/mainsubs.cpp b/phreeqcpp/mainsubs.cpp index 27e34981..efe65482 100644 --- a/phreeqcpp/mainsubs.cpp +++ b/phreeqcpp/mainsubs.cpp @@ -1671,6 +1671,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