From e8ae8322eb5abc9710321ff29fbd64d30892a110 Mon Sep 17 00:00:00 2001 From: David Parkhurst Date: Sun, 6 May 2018 21:06:18 -0600 Subject: [PATCH] gammas finished, working on reactants --- IPhreeqc.cpp | 8 ++ IPhreeqc.hpp | 20 ++++ phreeqcpp/PPassemblage.cxx | 17 +++ phreeqcpp/PPassemblage.h | 2 +- phreeqcpp/Phreeqc.cpp | 240 +++++++++++++++++++++++++++++++++++++ phreeqcpp/Phreeqc.h | 6 + 6 files changed, 292 insertions(+), 1 deletion(-) diff --git a/IPhreeqc.cpp b/IPhreeqc.cpp index 4c1de513..3bffcb43 100644 --- a/IPhreeqc.cpp +++ b/IPhreeqc.cpp @@ -554,6 +554,14 @@ std::list< std::string > IPhreeqc::ListComponents(void) { this->Components.clear(); this->PhreeqcPtr->list_components(this->Components); + this->PhreeqcPtr->list_EquilibriumPhases(this->EquilibriumPhasesList); + this->PhreeqcPtr->list_GasComponents(this->GasComponentsList); + this->PhreeqcPtr->list_KineticReactions(this->KineticReactionsList); + this->PhreeqcPtr->list_SolidSolutions(this->SolidSolutionComponentsList,this->SolidSolutionNamesList); + this->PhreeqcPtr->list_Surfaces(this->SurfaceTypeList, this->SurfaceNamesList); + this->PhreeqcPtr->list_Exchangers(this->ExchangeNamesList); + //this->PhreeqcPtr->list_ExchangeSpecies(this->es); + //this->PhreeqcPtr->list_SurfaceSpecies(this->es); this->UpdateComponents = false; } return this->Components; diff --git a/IPhreeqc.hpp b/IPhreeqc.hpp index 5a2b71ae..3bb387e0 100644 --- a/IPhreeqc.hpp +++ b/IPhreeqc.hpp @@ -945,6 +945,26 @@ protected: std::vector< std::string > DumpLines; std::list< std::string > Components; + std::list< std::string > EquilibriumPhasesList; + const std::list & IPhreeqc::GetEquilibriumPhasesList() { return this->EquilibriumPhasesList; }; + std::list< std::string > GasComponentsList; + const std::list & IPhreeqc::GetGasComponentsList() { return this->GasComponentsList; }; + std::list< std::string > KineticReactionsList; + const std::list & IPhreeqc::GetKineticReactionsList() { return this->KineticReactionsList; }; + std::list< std::string > SolidSolutionComponentsList; + const std::list & IPhreeqc::GetSolidSolutionComponentsList() { return this->SolidSolutionComponentsList; }; + std::list< std::string > SolidSolutionNamesList; + const std::list & IPhreeqc::GetSolidSolutionNamesList() { return this->SolidSolutionComponentsList; }; + std::list< std::string > SurfaceSpeciesList; + const std::list & IPhreeqc::GetSurfaceSpeciesList() { return this->SurfaceSpeciesList; }; + std::list< std::string > SurfaceTypeList; + const std::list & IPhreeqc::GetSurfaceTypeList() { return this->SurfaceTypeList; }; + std::list< std::string > SurfaceNamesList; + const std::list & IPhreeqc::GetSurfaceNamesList() { return this->SurfaceNamesList; }; + std::list< std::string > ExchangeSpeciesList; + const std::list & IPhreeqc::GetExchangeSpeciesList() { return this->ExchangeSpeciesList; }; + std::list< std::string > ExchangeNamesList; + const std::list & IPhreeqc::GetExchangeNamesList() { return this->ExchangeNamesList; }; std::map< int, std::string > SelectedOutputFileNameMap; diff --git a/phreeqcpp/PPassemblage.cxx b/phreeqcpp/PPassemblage.cxx index aed9983b..9af480db 100644 --- a/phreeqcpp/PPassemblage.cxx +++ b/phreeqcpp/PPassemblage.cxx @@ -248,6 +248,23 @@ cxxPPassemblage::totalize(Phreeqc * phreeqc_ptr) } return; } +std::set +cxxPPassemblage::GetPhases(Phreeqc * phreeqc_ptr) +{ + std::set phase_list; + // component structures + for (std::map < std::string, cxxPPassemblageComp >::iterator it = + pp_assemblage_comps.begin(); it != pp_assemblage_comps.end(); ++it) + { + int l; + phase * phase_ptr = phreeqc_ptr->phase_bsearch((*it).second.Get_name().c_str(), &l, FALSE);; + if (phase_ptr != NULL) + { + phase_list.insert(phase_ptr->name); + } + } + return phase_list; +} void cxxPPassemblage::add(const cxxPPassemblage & addee, LDBLE extensive) // diff --git a/phreeqcpp/PPassemblage.h b/phreeqcpp/PPassemblage.h index 5b735ad3..9efa21e7 100644 --- a/phreeqcpp/PPassemblage.h +++ b/phreeqcpp/PPassemblage.h @@ -49,7 +49,7 @@ class cxxPPassemblage:public cxxNumKeyword void Set_new_def(bool tf) {this->new_def = tf;} cxxPPassemblageComp *Find(const std::string name); - + std::set cxxPPassemblage::GetPhases(Phreeqc * phreeqc_ptr); void totalize(Phreeqc * phreeqc_ptr); void Serialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles); void Deserialize(Dictionary & dictionary, std::vector < int >&ints, std::vector < double >&doubles, int &ii, int &dd); diff --git a/phreeqcpp/Phreeqc.cpp b/phreeqcpp/Phreeqc.cpp index 55e52146..1f1d225c 100644 --- a/phreeqcpp/Phreeqc.cpp +++ b/phreeqcpp/Phreeqc.cpp @@ -169,6 +169,246 @@ size_t Phreeqc::list_components(std::list &list_c) } return(list_c.size()); } +size_t Phreeqc::list_EquilibriumPhases(std::list &list_pp) +/* +* Find all elements in any class definition +*/ +{ + std::set accumulator; + // pure phases + { + std::map::const_iterator cit = Rxn_pp_assemblage_map.begin(); + for (; cit != Rxn_pp_assemblage_map.end(); cit++) + { + cxxPPassemblage entity = cit->second; + std::set pp = entity.GetPhases(this); + std::set::iterator ppit = pp.begin(); + for (; ppit != pp.end(); ppit++) + { + accumulator.insert(*ppit); + } + } + } + list_pp.clear(); + std::set::iterator it = accumulator.begin(); + for (; it != accumulator.end(); it++) + { + list_pp.insert(list_pp.end(),*it); + } + return(list_pp.size()); +} +size_t Phreeqc::list_GasComponents(std::list &list_gc) +/* +* Find all elements in any class definition +*/ +{ + std::set accumulator; + // pure phases + { + std::map::const_iterator cit = Rxn_gas_phase_map.begin(); + for (; cit != Rxn_gas_phase_map.end(); cit++) + { + cxxGasPhase entity = cit->second; + std::vector &gc = entity.Get_gas_comps(); + for (size_t i = 0; i < gc.size(); i++) + { + int j; + phase * p = phase_bsearch(gc[i].Get_phase_name().c_str(), &j, 0); + accumulator.insert(p->name); + } + } + } + list_gc.clear(); + std::set::iterator it = accumulator.begin(); + for (; it != accumulator.end(); it++) + { + list_gc.insert(list_gc.end(), *it); + } + return(list_gc.size()); +} +size_t Phreeqc::list_KineticReactions(std::list &list_kr) +/* +* Find all kinetic reactions +*/ +{ + std::set accumulator; + // Kinetics + { + std::map::const_iterator cit = Rxn_kinetics_map.begin(); + for (; cit != Rxn_kinetics_map.end(); cit++) + { + cxxKinetics entity = cit->second; + for (size_t i = 0; i < entity.Get_kinetics_comps().size(); i++) + { + std::string ratename = entity.Get_kinetics_comps()[i].Get_rate_name(); + int j; + rate *r = rate_search(ratename.c_str(), &j); + if (r != NULL) + { + accumulator.insert(r->name); + } + } + } + } + list_kr.clear(); + std::set::iterator it = accumulator.begin(); + for (; it != accumulator.end(); it++) + { + list_kr.insert(list_kr.end(), *it); + } + return(list_kr.size()); +} +size_t Phreeqc::list_SolidSolutions(std::list &list_comps, std::list &list_names) +/* +* Find all elements in any class definition +*/ +{ + std::vector< std::set > ss_sets; + std::vector ss_names; + // solid solutions + std::map::const_iterator cit = Rxn_ss_assemblage_map.begin(); + // Fill vectors, ss names and related set of component names + for (; cit != Rxn_ss_assemblage_map.end(); cit++) + { + cxxSSassemblage entity = cit->second; + std::map &SSs = entity.Get_SSs(); + std::map::iterator ssit = SSs.begin(); + for (; ssit != SSs.end(); ssit++) + { + std::string ssname = ssit->second.Get_name(); + std::set accumulator_phases; + for (int i = 0; i < ssit->second.Get_ss_comps().size(); i++) + { + std::string pname = ssit->second.Get_ss_comps()[i].Get_name(); + int j; + phase * p = phase_bsearch(pname.c_str(), &j, 0); + accumulator_phases.insert(p->name); + } + ss_names.push_back(ssname); + ss_sets.push_back(accumulator_phases); + } + } + // need to merge into exclusive sets of solid solution components + bool repeat = true; + while (repeat) + { + repeat = false; + for (int i = 0; i < (int) ss_sets.size() - 1; i++) + { + for (int j = i + 1; j < (int) ss_sets.size(); j++) + { + // locate any common component + std::set::iterator it = ss_sets[j].begin(); + for (; it != ss_sets[j].end(); it++) + { + if (ss_sets[i].find(*it) != ss_sets[i].end()) + { + repeat = true; + break; + } + } + // merge sets and clear second set + if (repeat) + { + for (it = ss_sets[j].begin(); it != ss_sets[j].end(); it++) + { + ss_sets[i].insert(*it); + } + ss_sets[j].clear(); + break; + } + } + if (repeat) break; + } + } + list_comps.clear(); + list_names.clear(); + // Write lists + for (size_t i = 0; i < ss_sets.size(); i++) + { + std::set::iterator it = ss_sets[i].begin(); + for (; it != ss_sets[i].end(); it++) + { + list_names.push_back(ss_names[i]); + list_comps.push_back(*it); + } + } + return(list_comps.size()); +} +size_t Phreeqc::list_Surfaces(std::list &list_surftype, std::list &list_surfname) +/* +* Find all surface types and surfaces +*/ +{ + std::set > accumulator; + // Surfaces + { + std::map::const_iterator cit = Rxn_surface_map.begin(); + for (; cit != Rxn_surface_map.end(); cit++) + { + cxxSurface entity = cit->second; + std::vector &scomps = entity.Get_surface_comps(); + std::vector &scharges = entity.Get_surface_charges(); + for (size_t i = 0; i < scomps.size(); i++) + { + std::pair p(scomps[i].Get_master_element(), scomps[i].Get_charge_name()); + accumulator.insert(p); + } + } + } + list_surftype.clear(); + list_surfname.clear(); + std::set >::iterator it = accumulator.begin(); + for (; it != accumulator.end(); it++) + { + list_surftype.push_back(it->first); + list_surfname.push_back(it->second); + } + return(list_surfname.size()); +} +size_t Phreeqc::list_Exchangers(std::list &list_exname) +/* +* Find all exchangers +*/ +{ + std::set accumulator; + // Exchangers + std::map::const_iterator cit = Rxn_exchange_map.begin(); + for (; cit != Rxn_exchange_map.end(); cit++) + { + cxxExchange entity = cit->second; + std::vector &ecomps = entity.Get_exchange_comps(); + for (size_t i = 0; i < ecomps.size(); i++) + { + std::string exname = ""; + cxxNameDouble nd = ecomps[i].Get_totals(); + cxxNameDouble::iterator it = nd.begin(); + for (; it != nd.end(); it++) + { + struct master *m = master_bsearch(it->first.c_str()); + if (m != NULL) + { + if (m->type == EX) + { + exname = it->first; + break; + } + } + } + if (exname != "") + { + accumulator.insert(exname); + } + } + } + list_exname.clear(); + std::set< std::string>::iterator it = accumulator.begin(); + for (; it != accumulator.end(); it++) + { + list_exname.push_back(*it); + } + return(list_exname.size()); +} Phreeqc::Phreeqc(PHRQ_io *io) { // phrq_io diff --git a/phreeqcpp/Phreeqc.h b/phreeqcpp/Phreeqc.h index d02e2326..63653042 100644 --- a/phreeqcpp/Phreeqc.h +++ b/phreeqcpp/Phreeqc.h @@ -1157,6 +1157,12 @@ public: void set_phast(int); int next_user_number(Keywords::KEYWORDS key); size_t list_components(std::list &list_c); + size_t Phreeqc::list_EquilibriumPhases(std::list &list_pp); + size_t Phreeqc::list_GasComponents(std::list &list_gc); + size_t Phreeqc::list_KineticReactions(std::list &list_kr); + size_t Phreeqc::list_SolidSolutions(std::list &list_comps, std::list &list_names); + size_t Phreeqc::list_Surfaces(std::list &surftype, std::list &surf); + size_t Phreeqc::list_Exchangers(std::list &ex); PHRQ_io * Get_phrq_io(void) {return this->phrq_io;} void Set_run_cells_one_step(const bool tf) {this->run_cells_one_step = tf;}